为什么用Weekyear解析日期会返回错误的年份? [英] Why does parsing a date with weekyear return the wrong year?
本文介绍了为什么用Weekyear解析日期会返回错误的年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DateTime time=DateTimeFormat.forPattern("yyyy-ww").parseDateTime("2013-01");
其中DateTimeFormat
是org.joda.time.format.DateTimeFormat
.
执行上述操作时,时间变为2013-12-30T00:00:00.000
我究竟做错了什么?这是一个错误吗?我希望它是2013年的第一周,而不是最后一周.
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.
推荐答案
请参见此处.
w
(星期)的周模式字母应与x
(星期)一起使用.摘自 DateTimeFormat
的javadoc
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
将样式更改为
DateTimeFormat.forPattern("xxxx-ww")
您将解析为
2012-12-31T00:00:00.000-08:00
根据您的Locale
,2013年的第一周始于2012年.
Depending on your Locale
, the first week of 2013 started in 2012.
这篇关于为什么用Weekyear解析日期会返回错误的年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文