Java里的日期和时间学习

Date date = new Date();//yyyy-mm-dd hh:mm:ss[.fffffffff]
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.0");
		System.out.println("现在的日期时间是:" + sdf.format(date));;
		Calendar c = Calendar.getInstance();
	//	c.setTime(date);
		int second = c.get(Calendar.SECOND);
		System.out.println("现在的小时是"+second);
		
		int second2 = c.get(c.SECOND);
		System.out.println(second2);
		//拿到当前系统时间
		System.out.println(System.currentTimeMillis());
		
		//时区
		Calendar japan = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
		System.out.println(japan.get(Calendar.HOUR_OF_DAY));
		//打印时区ID
		for (String timezone : TimeZone.getAvailableIDs()) {
			System.out.println("时区的id  " + timezone);
		}


posted @ 2013-06-23 17:31  爱生活,爱编程  阅读(253)  评论(0编辑  收藏  举报