开发者

How to properly store GMT offset?

So recently I stor开发者_如何学运维ed all my locations with their GMT offset as integers (-12 to 12) and everything was ok, but now I have to add more locations, and I noticed that some of them are in timezones with GMT +05:30 and even +05:45. How do you store these? Like +5.5 or 5.75?

Regards, Briedis


The solution is pretty simple: Don't do it. Store the related timezone name (e.g. "Europe/Berlin") instead of the GMT offset ("GMT+1").


The common format for that is shhmm where s is the sign, hh are hours and mm are minutes (e.g., +0530 or -0500).


The best option is to store Datetime as UTC and store the offset as Time, so you can always refer back to the correct Datetime in history by adjusting it with the offset. You can also store the time zone in a third field so you know which time zone it came from.


You could add a second integer column for minute offset, with default of 0 since it will be for the majority of entries.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜