时区转换时注意夏令时的影响

mysql> select @@time_zone;
+-------------+
| @@time_zone |
+-------------+
| SYSTEM      |
+-------------+

mysql> select takeoff_time, last_send_notice_date, hide_date from matchedVideo where id = 3072;
+---------------------+-----------------------+---------------------+
| takeoff_time        | last_send_notice_date | hide_date           |
+---------------------+-----------------------+---------------------+
| 2012-11-10 00:00:00 |   2012-10-29 03:25:53 | 2012-10-24 11:57:41 |
+---------------------+-----------------------+---------------------+
1 row in set (0.01 sec)

mysql> set time_zone = '-0:00';

Query OK, 0 rows affected (0.00 sec)

mysql> select takeoff_time, last_send_notice_date, hide_date from matchedVideo where id = 3072;
+---------------------+-----------------------+---------------------+
| takeoff_time        | last_send_notice_date | hide_date           |
+---------------------+-----------------------+---------------------+
| 2012-11-10 08:00:00 |   2012-10-29 10:25:53 | 2012-10-24 18:57:41 |
+---------------------+-----------------------+---------------------+
1 row in set (0.00 sec)

mysql> set time_zone = '-7:00';
Query OK, 0 rows affected (0.00 sec)
mysql> select takeoff_time, last_send_notice_date, hide_date from matchedVideo where id = 3072;
+---------------------+-----------------------+---------------------+
| takeoff_time        | last_send_notice_date | hide_date           |
+---------------------+-----------------------+---------------------+
| 2012-11-10 01:00:00 |   2012-10-29 03:25:53 | 2012-10-24 11:57:41 |
+---------------------+-----------------------+---------------------+
1 row in set (0.01 sec)

第一条sql是没有强制设置过时区信息时执行的,按照系统所在时区进行查询;第二条执行前设置时区为0时,takeoff_time增加了8个小时,而last_send_notice_date和hide_date都只增加了7个小时;同样,第三条sql执行前我们设置为-7时区时,takeoff_time增加了1个小时,而last_send_notice_date和hide_date都和第一条sql执行出的结果一致

为什么会发生这样的事情呢?

登录机器查看时区

root@aaa:~# date
Tue Oct 30 22:56:25 PDT 2012

发现PDT,PDT全称是Pacific Daylight Time(太平洋夏季时间)

通过百度百科可以了解到:
PDT转换成北京时间方法  PDT从每年3月的第二个星期日到11月的第一个星期日期间和北京时间15小时,其余月份和北京时间差16小时 。也就是说每年3月的第二个星期日到11月的第一个星期日期间处于-7时区,其余月份处于-8时区。由此可以知道为什么上面三个sql会有这样的区别!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值