我正在编写将跟踪文件的软件,如果它们发生更改,我应该使用 UTC
我正在编写一些软件来跟踪文件是否已被检出和更改。该文件可以由多个不同时区的不同人员查看和更改。
所以,简单地说,我会做这样的事情:
if ( checked_out_file.last_modified_date > my_database_record_of_the_last_modified_date ) {
// file has changed since last sync so do something
}
上面只是伪代码,所以不要纠结于什么语言和类似的事情。我基本上想知道的是,我是否应该将 my_database_record_of_the_last_modified_date 存储为 UTC 时间,并且当我进行 checked_out_file.last_modified_date 比较时,如上面的伪代码所示,应该我也用UTC时间吗?
I'm writing some software to track if a file has been checked out and changed. The file could be checked out and changed by various people in several different time zones.
So, simply put I would be doing something like this:
if ( checked_out_file.last_modified_date > my_database_record_of_the_last_modified_date ) {
// file has changed since last sync so do something
}
The above is just pseudo-code so don't get hung up on what language and things like that. What I am basically wondering is should I store the my_database_record_of_the_last_modified_date
as the UTC time, and when I do my checked_out_file.last_modified_date
comparison, as illustrated in my pseudo-code above, should I also use the UTC time for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
时间是一种痛苦的工作。时区情况更糟。对此你无能为力。但如果您到处都使用UTC,您可以让时间变得更容易忍受。
以 UTC 格式存储所有日期。使用 UTC 进行所有日期比较。在 UTC 中尽你所能。理想情况下,日期不会采用 UTC 的唯一时间是当它被格式化以显示给用户时。时区是一个你不想掉进去的兔子洞。
希望这有帮助!
PS:是的,我过去在时区方面有过不好的经历。你能告诉吗?
Time is a pain to work with. Time zones are even worse. There's not much you can do about that. But if you use UTC everywhere, you can make time a little more bearable.
Store all your dates in UTC. Do all your date comparisons in UTC. Do everything you possibly can in UTC. Ideally, the only time a date won't be in UTC is when it's being formatted for display to a user. Time zones are a rabbit hole you do not want to go down.
Hope this helps!
PS: Yes, I've had bad experiences with time zones in the past. Could you tell?