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

后端 未结 1 542
心在旅途
心在旅途 2021-01-24 10:33
DateTime time=DateTimeFormat.forPattern(\"yyyy-ww\").parseDateTime(\"2013-01\"); 

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

1条回答
  •  迷失自我
    2021-01-24 11:37

    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.

    0 讨论(0)
提交回复
热议问题