2013-10-05 39 views

回答

0

使用Joda Time's提供的ISODateTimeFormat
它具有以下的方法:

  • ISODateTimeFormat.weekyearWeekDay()ISODateTimeFormat.weekDate()(對於格式如2009-W01-1
  • ISODateTimeFormat.weekyearWeek()(對於格式如2009-W01
  • ISODateTimeFormat.basicWeekDate()(爲緊湊的格式,如2009W011

它們可以這樣使用:

ReadableDateTime endOfYearDateTime = DateTime.parse("2008-12-29T13:06Z"); 
logger.info("endOfYearDateTime  : {}", endOfYearDateTime); 

String endOfYearISOWeekDateString = ISODateTimeFormat.weekyearWeekDay().print(endOfYearDateTime); 
logger.info("isoCalendarWeekDateString: {}", endOfYearISOWeekDateString); 

ReadableDateTime reverseEndOfYearDateTime = ISODateTimeFormat.weekyearWeekDay().parseDateTime(endOfYearISOWeekDateString); 
logger.info("reverseEndOfYearDateTime : {}", reverseEndOfYearDateTime); 

上面的代碼將記錄以下數據:

endOfYearDateTime  : 2008-12-29T13:06:00.000Z 
isoCalendarWeekDateString: 2009-W01-1 
reverseEndOfYearDateTime : 2008-12-29T00:00:00.000+01:00 
相關問題