Joda Time 错误地解释了 AM/PM
我将 DateTimes
作为 timestamps
存储在我的 MySQL 数据库中。 Joda Time 错误地解释了这些 DateTimes
的 AM/PM 部分。
DateTime dt = new DateTime(1324231621L * 1000); // long pulled from DB as timestamp
DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm aa z");
String timeStr = fmt.print(dt);
上述结果应为 12:07 AM CST
,但结果却为 12:07 PM CST
。
它看起来像是将时间解释为 24 小时制,但我使用的是小写“h”,所以我不知道为什么。真正的原因是什么?
I'm storing DateTimes
as timestamps
in my MySQL database. Joda Time is interpreting the AM/PM part of these DateTimes
incorrectly.
DateTime dt = new DateTime(1324231621L * 1000); // long pulled from DB as timestamp
DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm aa z");
String timeStr = fmt.print(dt);
The above should result in 12:07 AM CST
but instead results in 12:07 PM CST
.
It looks like it's interpreting the hours as 24-hour based, but I'm using a lowercase "h", so I don't know why. What's the real reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您得到了错误的值 - 时间戳是 2011-12-18T18:07:01 UTC - 所以它是 CST 下午 12:07。如果本来是中午 12:07,那就表明将其转换成长格式的过程中涉及的任何问题都是有问题的 - 无论是将其放入数据库的过程,还是您的方式已从数据库中提取它。
I think you've got the wrong value - that timestamp is 2011-12-18T18:07:01 UTC - so it is 12:07pm in CST. If it was meant to be 12:07am, that would suggest that whatever was involved in getting it into the long form to start with is at fault - whether that's the process which put it in the database to start with, or the way that you've pulled it from the database.