通过java代码往mysql数据库中写入日期相关数据少13个小时
通过show variables like '%time_zone%';
查看时区:
CST 时区
名为 CST 的时区是一个很混乱的时区,有四种含义:
- 美国中部时间 Central Standard Time (USA) UTC-06:00
- 澳大利亚中部时间 Central Standard Time (Australia) UTC+09:30
- 中国标准时 China Standard Time UTC+08:00
- 古巴标准时 Cuba Standard Time UTC-04:00
如果你遇到时间不对的情况,CST代表的不是中国标准时间
解决方法:
解决方案
解决办法也很简单,明确指定 MySQL 数据库的时区,不使用引发误解的 CST :
mysql> set global time_zone = '+08:00';
Query OK, 0 rows affected (0.00 sec)
mysql> set time_zone = '+08:00';
Query OK, 0 rows affected (0.00 sec)
或者修改 my.cnf 文件,在 [mysqld] 节下增加 default-time-zone = '+08:00' 。
修改时区操作影响深远,需要重启 MySQL 服务器,建议在维护时间进行。
hello world!!!

浙公网安备 33010602011771号