Java日期时间偏移/时区类?

发布于 2025-01-14 00:58:16 字数 417 浏览 1 评论 0原文

好吧,这似乎是在课堂上的某个地方完成或处理的,但不确定。 问题是我有一个带有开始和结束时间的事件对象。然后有一个主要的“日”对象与之比较。现在的问题是一切都是 UTC,所以一切正常。因此,当用户更改事件对象以在事件上使用偏移量为 -5 的东部时间时,它会与 UTC 时间的这一天对象进行比较,因此当然您可以得到与主“日”对象的重叠,因为它的两个不同时区被比较互相对抗。这当然是假的。现在代码正在比较日期 getTimeMillis 以查看结束日期时间(以毫秒为单位)是否小于 Day 对象 23:59 UTC 时间,或者对象开始时间是否大于 Day 对象开始时间 00:01。 那么...是否有一个类,我可以简单地传递两个日期时间(以毫秒为单位)、时区,并获得处理所有这些偏移量的是/否答案? 我当然可以使用“afterDate”或“beforeDate”的东西手动完成这一切,但希望已经有一些奇特的构建来处理这一切了?

Ok this seems like its been done or handled somewhere in a class but not sure.
Problem is I have an event object with a start and end time. Then there is a main "day" object its compared against. Problem now is everything is UTC so it all works fine. So when user changes event object to use say eastern time with offset -5 on the event, its being compared against this day object with UTC time so of course you can get overlaps against the main "day" object because its two different timezones being compared against each other. This is of course bogus. Right now code is comparing date getTimeMillis to see if the end date time in millis is less than Day objects 23:59 UTC time or if the objects start time is greater than the Day object start time of 00:01.
So... is there a class out there that I can simply pass in the two date time's in millis, time zone and get a yes/no answer that handles all these offsets?
I of course could do it all manually using the "afterDate" or "beforeDate" stuff but was hoping there is some fancy built already to handle it all already?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文