Joda Time 错误地解释了 AM/PM

发布于 2024-12-21 22:57:06 字数 471 浏览 5 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も星光 2024-12-28 22:57:06

我认为您得到了错误的值 - 时间戳是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文