环境:centOS 7.9
lsb_release -a
Operating System: CentOS Linux 7 (Core)
1、操作系统时区设置
#Linux中我们可以使用`date -R`查看本地时区
date -R
#或者直接使用date查看的是CST的时区
1.1、timedatectl list-timezones 可以查看所有可以设置的时区
# 列出伦敦 时区设置
timedatectl list-timezones | grep 'London'
Europe/London
1.2、设置时区
timedatectl set-timezone Europe/London
1.3、使用timedatectl
命令也可以看到时区已经修改
timedatectl
Local time: Sun 2023-12-17 05:23:08 GMT
Universal time: Sun 2023-12-17 05:23:08 UTC
RTC time: Sun 2023-12-17 05:23:08
Time zone: Europe/London (GMT, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2023-10-29 01:59:59 BST
Sun 2023-10-29 01:00:00 GMT
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2024-03-31 00:59:59 GMT
Sun 2024-03-31 02:00:00 BST
2、mysql时区
-- 1、查看系统时区: @@global.system_time_zone
-- 2、查看全局时区 @@global.time_zone
-- 3、查看客户端时区 @@session.time_zone
SELECT @@global.time_zone, @@session.time_zone,@@global.system_time_zone;
如下设置与SYSTEM相关,及系统时间与OS一致
如果需要设置,请参考文档: