简体   繁体   English

什么是处理时区经常变化的最佳实践

[英]What's the best practices to handle frequently changing timezones

I'm writing a toy logistics service. 我正在写玩具物流服务。 As a result, products will travel through lots of different timezones, and I'll need to query both the strict ordering of events, as well as what hour of day it is for products (for example, what happened when the sun was at its hottest, at 1200). 结果,产品将穿越许多不同的时区,因此我需要查询事件的严格排序以及产品在一天中的什么时间(例如,当太阳在其最热,在1200)。

At the moment, I'm saving jodatime DateTimes and trying to deal with them exclusively, but I know time is mighty tricky, and I'm wondering if I need to do anything else to make sure it all works. 目前,我正在保存jodatime DateTimes并尝试专门处理它们,但是我知道时间是非常棘手的,我想知道是否需要做其他任何事情来确保所有功能都可以正常工作。

Given that you're recording events as they occur (rather than planning for future events), you probably don't need to worry about changes to time zone rules which occur in the future. 鉴于您正在记录事件的发生(而不是计划将来的事件),因此您可能不必担心将来会发生的时区规则更改。

As such, it would be reasonable to store a timestamp (eg as UTC) and also the time zone ID for the location of the event. 这样,存储时间戳(例如,UTC)以及事件位置的时区ID是合理的。 To make querying easier, you could also store the local time at the time of the event. 为了简化查询,您还可以在事件发生时存储本地时间。 Just be aware that as a toy is travelling through time zones, there could be multiple events at different instants in time, all of which occur at "midday" on the same day (but in different zones). 请注意,当玩具在时区中行驶时,可能会在不同的时间瞬间发生多个事件,所有这些事件都发生在同一天的“中午”(但在不同的区域)。 You really need to think carefully about what queries you really want to perform on the local date/time values. 您确实需要仔细考虑您真正想对本地日期/时间值执行哪些查询。

I am not familiar with jodatime but when I need to store the time I always enjoy using Epoch time because it is very easy to manipulate to get different formats. 我对jodatime并不熟悉,但是当我需要存储时间时,我总是喜欢使用Epoch time,因为它很容易操纵以获取不同的格式。 If you're interested in it here is a converter website that I find very helpful: http://www.epochconverter.com/ 如果您对此感兴趣,可以在这里找到一个转换器网站,该网站对我很有帮助: http : //www.epochconverter.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 最佳实践:什么是处理字节协议的最佳方法 - Best practices: What's the best way to treat byte protocol 什么是Java最佳实践来处理枚举 - what is Java best practice to handle enum's 在 Spring 和 Hibernate 中同时处理控制器、服务和 DAO 层异常的最佳实践是什么 - What are the best practices to handle exception at Controller, Service and DAO Layer simultaneously in Spring & Hibernate Facade模式的最佳实践是什么? - What are the best practices for Facade pattern? 关于从基准状态更改状态的最佳实践 - jmh best practices on changing state from benchmarks PriorityQueue经常需要调整比较器 - 我该如何处理这个? - PriorityQueue with frequently need to adjust the Comparator - How do I handle this best? 处理此“ try-error-clean -retry”情况的最佳方法是什么? - What's the best way to handle this “try - error - clean -retry” case? 在UI端处理ResponseEntity的最佳方法是什么? - What's the best way to handle ResponseEntity on UI side? 可完成的期货。 处理业务“例外”的最佳方法是什么? - Completable futures. What's the best way to handle business “exceptions”? 使用GSON处理JSON API响应的最佳方法是什么? - What's the best way to handle JSON API responses using GSON?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM