为什么用周年解析日期返回错误的年份?

问题描述 投票:0回答:1
DateTime time=DateTimeFormat.forPattern("yyyy-ww").parseDateTime("2013-01"); 

其中DateTimeFormatorg.joda.time.format.DateTimeFormat

[执行上述操作时,时间变为2013-12-30T00:00:00.000我究竟做错了什么?这是错误吗?我希望它是2013年的第一周,而不是最后一周。

java scala jodatime
1个回答
2
投票

请参见here

w,周年的周,模式字母应与x,周年一起使用。从javadoc of DateTimeFormat

DateTimeFormat

将样式更改为

 x       weekyear                     year          1996
 w       week of weekyear             number        27

您将解析为

DateTimeFormat.forPattern("xxxx-ww")

根据您的2012-12-31T00:00:00.000-08:00 ,2013年的第一周是从2012年开始。

© www.soinside.com 2019 - 2024. All rights reserved.