今天跟别人讨论才突然发现了这个严重的问题,不能用int来存放时间,时间应该用datetime,当时为何用int来存放,为了防止时区问题,所以用int,然后起初是研究discuz代码,看到他的所有时间都是用int类型来存放 ……
现在如果使用int类型存放时间,2039年之后的时间无法转换,都是0.
mysql> set @tm = '2049-01-02';
Query OK, 0 rows affected (0.01 sec)
mysql> set @unix = unix_timestamp(@tm);
Query OK, 0 rows affected (0.00 sec)
mysql> select @tm,@unix,from_unixtime(@unix);
+------------+-------+----------------------+
| @tm | @unix | from_unixtime(@unix) |
+------------+-------+----------------------+
| 2049-01-02 | 0 | 1970-01-01 08:00:00 |
+------------+-------+----------------------+
1 row in set (0.00 sec)
mysql> select @tm,@unix,from_unixtime(@unix),unix_timestamp(now());
+------------+-------+----------------------+-----------------------+
| @tm | @unix | from_unixtime(@unix) | unix_timestamp(now()) |
+------------+-------+----------------------+-----------------------+
| 2049-01-02 | 0 | 1970-01-01 08:00:00 | 1625320054 |
+------------+-------+----------------------+-----------------------+
1 row in set (0.00 sec)