joda time 方便快捷 .
操作日期不再那么麻烦
?
? DateTime dt = new DateTime("2010-10-01");
? //今天
??System.out.println(dt.toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
??//明天
??System.out.println(dt.plus(Period.days(1)).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")));
??//昨天
??System.out.println(dt.plus(Period.days(-1)).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")));
??//2000年的现在两小时后
??DateTime dt2 = new DateTime();
??DateTime year2000 = dt2.withYear(2000);
??DateTime twoHoursLater = year2000.plusHours(2);
??System.out.println(twoHoursLater.toString(DateTimeFormat.forPattern("yy-MM-dd HH:mm:ss")));
????
???String monthName = dt.monthOfYear().getAsText();//十二月
???String dayName = dt.dayOfWeek().getAsText();//星期二
???String date = dt.dayOfYear().getAsText();//在一年里第多少天
?
??? //两个日期间差多少天
??? DateTime dd = new DateTime("2010-10-01");
??? DateTime dt = new DateTime("2010-10-03");
??? Days d = Days.daysBetween(dd, dt);
??? System.out.println(d.getDays());
??
??? 更多示例参见官网:http://joda-time.sourceforge.net/