mysql中用于时区的数据类型 [英] data type to use in mysql for timezones
问题描述
我将日期/时间存储在我的UTC数据库中.我正在努力在用户选择时区时添加对此的转换,以使其显示他们的本地时间.基本上,用户从表单中进行选择:
I store a date/time in my database that is UTC. I'm working to add conversion of this once a user selects a timezone so it shows local time for them. Basically the user selects from a form:
<select name="DropDownTimezone" id="DropDownTimezone">
<option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="-11.0">(GMT -11:00) Midway Island, Samoa</option>
<option value="-10.0">(GMT -10:00) Hawaii</option>
...
我可以使选项值成为我想要的任何值,但如上所述很容易记住.我将为mysql使用哪种数据类型?在这种情况下真的重要吗? TINYINT会做吗?也许使用ENUM是个好主意?
I can make the option value anything I want but an easy to remember one is as above. What data type would I use for mysql? Does it really matter in this case? Would TINYINT do? Maybe using an ENUM would be a good idea?
任何建议将不胜感激.
推荐答案
您提出的方案(将时区存储为距GMT的整数偏移量)在以下情况下可能会失败:
The scheme you're proposing (storing time zones as an integer offset from GMT) may fail for the following cases:
- 印度,该时间是UTC + 05:30(不是整数小时).
- 基里巴斯,在世界标准时间+ 14:00(超过12小时).
- 区分英国时间和格林尼治标准时间. (前者使用夏令时;后者则不是.)
- 区分使用相同的GMT偏移量但在一年中不同时间切换的一些国家/地区.
要获得全时区支持,我建议使用 zoneinfo
数据库并存储时区作为字符串(例如,"America/New_York").
For full time zone support, I'd recommend using the zoneinfo
database and storing time zones as strings (e.g, "America/New_York").
这篇关于mysql中用于时区的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!