数据类型/结构来存储MySQL中的时区偏移量 [英] Datatype/structure to store timezone offset in MySQL
问题描述
哪些是在MySQL中存储时区偏移的正确数据类型/结构?我只想存储数值(城市和国家显然存储在其他列中)。
Which would be the proper datatype/structure to store timezone offsets in MySQL? I just want to store the numeric value (the city and country are obviously stored in other columns).
示例:
- -5:00瓜亚基尔,ECU
- -4:30加拉加斯,VEN
- 0:00城市
- 2:00 Bonn,GER
- -5:00 Guayaquil, ECU
- -4:30 Caracas, VEN
- 0:00 Some city
- 2:00 Bonn, GER
推荐答案
您应该使用 TIME
。这是任务的正确数据类型:您有格式化和计算可用。此外,根据文档, TIME
也应该被用作两个时刻之间的差异的结果,这是Timezones实际上的差异。
You should use TIME
. It's the right data type for the task: you have formatting and calculations are available. Moreover, according to the docs, TIME
is also supposed to be used as a result of differences between two moments, which is what Timezones are in fact.
从文档:
MySQL在'HH检索并显示TIME值:MM:SS'格式(或
'HHH:MM:SS'格式为大小时值)。 TIME值可能在
'-838:59:59'到'838:59:59'之间。小时部分可能很大,因为
TIME类型不仅可以用于表示一天中的时间(
必须小于24小时),而且可以使用经过的时间或时间间隔$ b两个事件之间的$ b(可能远远大于24小时,甚至
为负)。
MySQL retrieves and displays TIME values in 'HH:MM:SS' format (or 'HHH:MM:SS' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).
这篇关于数据类型/结构来存储MySQL中的时区偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!