简体   繁体   中英

Why does parsing a date with weekyear return the wrong year?

DateTime time=DateTimeFormat.forPattern("yyyy-ww").parseDateTime("2013-01"); 

where DateTimeFormat is org.joda.time.format.DateTimeFormat .

When I execute the above, time becomes 2013-12-30T00:00:00.000 what am I doing wrong? Is this a bug? I expect it to be the first week of 2013, not the last.

See here .

The w , week of weekyear, pattern letter is meant to be used with x , weekyear. From the javadoc of DateTimeFormat

 x       weekyear                     year          1996
 w       week of weekyear             number        27

Change your pattern to

DateTimeFormat.forPattern("xxxx-ww")

and you'll parse to

2012-12-31T00:00:00.000-08:00

Depending on your Locale , the first week of 2013 started in 2012.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM