开发者

How to handle time zones in a CMS?

开发者 https://www.devze.com 2023-02-08 22:59 出处:网络
I\'m storing MySQL DateTimes in UTC, and let the user select their time zone, storing that information.

I'm storing MySQL DateTimes in UTC, and let the user select their time zone, storing that information.

However, I want to to some queries that uses group by a date. Is it开发者_C百科 better to store that datetime information in UTC (and do the calculation every time) or is it better to save it in the timezone given? Since time zones for users can change, I wonder.

Thanks


Generally always store in UTC and convert for display, it's the only sane way to do time differences etc. Or when somebody next year decides to change the summer time dates.


It's almost always better to save the time information in UTC, and convert it to local time when needed for presentation and display.

Otherwise, you will go stark raving mad trying to manipulate and compare dates and times in your system because you will have to convert each time to UTC time for comparison and manipulation.

0

精彩评论

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

关注公众号