gpt4 book ai didi

java - 为什么用Weekyear解析日期会返回错误的年份?

转载 作者:行者123 更新时间:2023-12-01 21:44:03 24 4
gpt4 key购买 nike

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


其中 DateTimeFormatorg.joda.time.format.DateTimeFormat

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

最佳答案

请参见here

w(星期)的星期模式字母应与x(星期)一起使用。从javadoc of DateTimeFormat

 x       weekyear                     year          1996
w week of weekyear number 27


将模式更改为

DateTimeFormat.forPattern("xxxx-ww")


然后您将解析为

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


根据您的 Locale,2013年的第一周始于2012年。

关于java - 为什么用Weekyear解析日期会返回错误的年份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58782968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com