1. 查看服務器時間結果也正常 CST
2. 查看數據庫
show variables like "%time_zone%";
//system_time_zone CST
//time_zone SYSTEM
select now();
//2020-06-06 13:49:35
3. 運行我的WEB應用後,時間竟相差了13個小時,一切的罪魁禍首就是CST是個比較混亂的時區。
CST時區(CST有4種含義)
- 美國中部時間 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
- 另外:美國從“3月11日”至“11月7日”實行夏令時,美國中部時間改爲 UTC-05:00,與 UTC+08:00 相差 13 小時
解決方案:
1. 修改 my.cnf
文件,在 [mysqld]
節下增加 default-time-zone = '+08:00'
(需要重啓 MySQL 服務器,建議在維護時間進行。)
2. 數據庫連接指定:serverTimezone (建議)
jdbc:mysql://xxx:3306/demo?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8