5. 当TIME_ZONE 不一样时
drop table if exists heyf;
create table heyf (id int ,curtime timestamp) type myisam;
set @@time_zone = '+8:00';
insert into heyf values (11,'2008-08-09 15:53:48');
(root@FuncTestDB:)> select * from heyf ;
+------+---------------------+
| id | curtime |
+------+---------------------+
| 11 | 2008-08-09 15:53:48 |
+------+---------------------+
1 row in set (0.00 sec)
(root@FuncTestDB:)> set @@time_zone = '+6:00';
Query OK, 0 rows affected (0.00 sec)
(root@FuncTestDB:)> select * from heyf ;
+------+---------------------+
| id | curtime |
+------+---------------------+
| 11 | 2008-08-09 13:53:48 |
+------+---------------------+
1 row in set (0.00 sec)
(root@FuncTestDB:)> set @@time_zone = '+4:00';
Query OK, 0 rows affected (0.00 sec)
(root@FuncTestDB:)> select * from heyf ;
+------+---------------------+
| id | curtime |
+------+---------------------+
| 11 | 2008-08-09 11:53:48 |
+------+---------------------+
1 row in set (0.00 sec)
我们看到,时间在随着TIME_ZONE的变化而变化;
timestamp 实际存储的是一个与'19700101000000'的时间差值(秒为单位),在提取时会根据当前的TIME_ZONE来重新计算.
所以我们在使用这种类型的数据时,要特别注意系统变量:TIME_ZONE。