解决mysql时区问题导致错误Incorrect datetime value: '1970-01-01 00:00:01'
mysql时区错误Incorrect datetime value: '1970-01-01 00:00:01'
手册中的描述:
A timestamp. The range is ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19
03:14:07’ UTC.
注意末尾的UTC,此为世界协调时,指的是经度0度上的标准时间。
官方文档中描述:
MySQL converts TIMESTAMP values from the current time zone to UTC for
storage, and back from UTC to the current time zone for retrieval.
(This does not occur for other types such as DATETIME.) By default,
the current time zone for each connection is the server’s time. The
time zone can be set on a per-connection basis. As long as the time
zone setting remains constant, you get back the same value you store.
If you store a TIMESTAMP value, and then change the time zone and
retrieve the value, the retrieved value is different from the value
you stored. This occurs because the same time zone was not used for
conversion in both directions. The current time zone is available as
the value of the time_zone system variable.
文中说到,在存储时会根据当前环境的的时区转换为UTC存储。
而环境中的时区为CST中国标准时间,比UTC要早8个小时,常见表示为GMT+0800 (中国标准时间)。
也正是如此,输入的值存储时需要加八个小时再存储,对应过来timestamp的时间范围表示为’1970-01-01 08:00:01’ and ‘2038-01-19 11:14:07’。
1970-01-01 08:00:00 时间由来
在用ng的date过滤服务的时候时间戳0会转换成1970-01-01 08:00:00;
是因为起源于UNIX系统,以Unix诞生的时间为参照确定的,UNIX认为1970年1月1日0点是时间纪元,现代计算机(电话,电子设备)时间以1970 年 1 月 1 日的 08:00为基准,
在时间转换时,或者时间重置时都会出现这个时间值,unix时间戳零点是 1970年1月1日0点整(utc),北京是gmt 8所以变成八点。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
MySQL 5.7.29 + Win64 解压版 安装教程图文详解
这篇文章主要介绍了MySQL 5.7.29 + Win64 解压版 安装教程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-05-05
mysql-8.0.16 winx64的最新安装教程图文详解
最近刚学习数据库,首先是了解数据库是什么,数据库、数据表的基本操作,这就面临了一个问题,mysql的安装,我这里下载的是64位的,基于Windows的,需要的朋友可以参考下2019-06-06
linux下mysql提示"mysql deamon failed to start"错误的解决方法
网站突然连接不上数据库,于是朋友直接重启了一下服务器。进到cli模式下,执行 service myqsld start 发现还是提示"mysql deamon failed to start"错误信息2013-04-04


最新评论