How to handle time zones in a CMS?
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.
精彩评论