开发者

I'm writing software that will be tracking files and if they are changed, should I be using 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, si开发者_StackOverflow社区mply 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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜