3 回答
TA贡献1808条经验 获得超4个赞
("SELECT DATE_ADD(my_datetime, INTERVAL 1 DAY)")
("SELECT UNIX_TIMESTAMP(my_datetime)")
TA贡献1816条经验 获得超4个赞
在MySQL 5和更高版本中,时间戳值从当前时区转换为UTC存储,并从UTC转换回当前时区进行检索。(这只发生在时间戳数据类型上,并且不对于其他类型,如datetime。)
默认情况下,每个连接的当前时区是服务器的时间。时区可以按每个连接设置,如MySQL服务器时区支持.
TA贡献1843条经验 获得超7个赞
下面的示例显示了TIMESTAMP更改后,日期类型更改了值。time-zone to 'america/new_york'哪里DATETIME没有变化。
mysql> show variables like '%time_zone%';
+------------------+---------------------+
| Variable_name | Value |
+------------------+---------------------+
| system_time_zone | India Standard Time |
| time_zone | Asia/Calcutta |
+------------------+---------------------+
mysql> create table datedemo(
-> mydatetime datetime,
-> mytimestamp timestamp
-> );
mysql> insert into datedemo values ((now()),(now()));
mysql> select * from datedemo;
+---------------------+---------------------+
| mydatetime | mytimestamp |
+---------------------+---------------------+
| 2011-08-21 14:11:09 | 2011-08-21 14:11:09 |
+---------------------+---------------------+
mysql> set time_zone="america/new_york";
mysql> select * from datedemo;
+---------------------+---------------------+
| mydatetime | mytimestamp |
+---------------------+---------------------+
| 2011-08-21 14:11:09 | 2011-08-21 04:41:09 |
+---------------------+---------------------+
添加回答
举报