Java DateTimeFormatter - 添加天数有时会提供错误的结果
目前我们已经实现了以下内容:
LocalDateTime actualDate = LocalDateTime.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd.MM.yyyy");
String fromDate = format.format(actualDate.plusDays(15));
String toDate = format.format(actualDate.plusDays(30));
大多数时候,它工作得很好。有时,一些疯狂的东西会显示为日期 - 例如:
toDate 被正确计算为 09.04.2022 - 但 fromDate 被计算为 02.20.9032,这看起来完全奇怪。 特别是,因为它只是偶尔发生,所以很难理解这里到底出了什么问题。
如果有任何建议或帮助,我将不胜感激。如果 plusDays(15) 有效,那么为什么 plusDays(30) 突然不应该起作用似乎很奇怪,反之亦然......并且它很少发生错误。
Currently we have implemented the following:
LocalDateTime actualDate = LocalDateTime.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd.MM.yyyy");
String fromDate = format.format(actualDate.plusDays(15));
String toDate = format.format(actualDate.plusDays(30));
Most of the time, it works perfectly fine. Sometimes, something wild appears as a Date - for example:
the toDate was correctly calculated to 09.04.2022 - but the fromDate was calculated as 02.20.9032, which seems totally odd.
Especially, as it only occurs occasionally, it is hard to understand what exactly is going wrong here.
I would kindly appreciate any advice or help on the same. If plusDays(15) works, it seems odd why plusDays(30) suddenly shouldn't and viceversa... and it does only rarely happen to be wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论