为什么 MySQL unix 时间会超出 32 位无符号整数限制?
mysql> SELECT FROM_UNIXTIME(2145916799), FROM_UNIXTIME(2145916800), POW(2,32-1)-1, 2145916799 - POW(2,32-1)-1;
+---------------------------+---------------------------+---------------+----------------------------+
| FROM_UNIXTIME(2145916799) | FROM_UNIXTIME(2145916800) | POW(2,32-1)-1 | 2145916799 - POW(2,32-1)-1 |
+---------------------------+---------------------------+---------------+----------------------------+
| 2037-12-31 18:59:59 | NULL | 2147483647 | -1566850 |
+---------------------------+---------------------------+---------------+----------------------------+
1 row in set (0.00 sec)
mysql>
第一个字段是我可以赋予 FROM_UNIXTIME
的最高可能值。下一个字段是该值加一,返回NULL
。第三个字段是无符号 32 位 int 的最大可能值。最终值是最高可能的 UNIXTIME 和最高可能的 int 之间的差值,略高于 18 天的秒数。它似乎在当地时区的 2037
末尾停止。有什么想法吗?这是其中一项计算中的自然断点吗?这只是 mysqld 中的任意限制吗?
mysql> SELECT FROM_UNIXTIME(2145916799), FROM_UNIXTIME(2145916800), POW(2,32-1)-1, 2145916799 - POW(2,32-1)-1;
+---------------------------+---------------------------+---------------+----------------------------+
| FROM_UNIXTIME(2145916799) | FROM_UNIXTIME(2145916800) | POW(2,32-1)-1 | 2145916799 - POW(2,32-1)-1 |
+---------------------------+---------------------------+---------------+----------------------------+
| 2037-12-31 18:59:59 | NULL | 2147483647 | -1566850 |
+---------------------------+---------------------------+---------------+----------------------------+
1 row in set (0.00 sec)
mysql>
The first field is the highest possible value I can give to FROM_UNIXTIME
. The next field is that value plus one which returns NULL
. The third field is the highest possible value for an unsigned 32 bit int. The final value is the difference between the highest possible UNIXTIME and the highest possible int which is a little over 18 days worth of seconds. It appears that it stops at the end of 2037
in the local timezone. Any ideas why? Is that a natural breaking point in one of the calculations? Is that just an arbitrary limit in mysqld
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常unix时间戳范围是从1970年1月1日到2037年12月31日
有关更多信息,请查看http://en.wikipedia.org/wiki/Year_2038_problem
normally unix timestamp range is from January 1st 1970 to December 31st 2037
for more information have a look at http://en.wikipedia.org/wiki/Year_2038_problem
我在 GMT+0200 得到了截然不同的结果。 i686 和 x86_64 的结果相同。
大概 2038-01-01 UTC 是不允许的。
I got very different results in GMT+0200. same results for both i686 and x86_64.
Propably 2038-01-01 UTC was not allowed.