我正在编写将跟踪文件的软件,如果它们发生更改,我应该使用 UTC

发布于 2024-10-17 19:10:56 字数 450 浏览 3 评论 0原文

我正在编写一些软件来跟踪文件是否已被检出和更改。该文件可以由多个不同时区的不同人员查看和更改。

所以,简单地说,我会做这样的事情:

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

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

发布评论

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

评论(1

孤君无依 2024-10-24 19:10:56

时间是一种痛苦的工作。时区情况更糟。对此你无能为力。但如果您到处都使用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?

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