用timedatectl命令查看当前服务器时区设置:
Local time: Mon 2017-03-27 20:14:15 CST Universal time: Mon 2017-03-27 12:14:15 UTC RTC time: Mon 2017-03-27 12:14:15 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 | Local time: Mon 2017-03-27 20:14:15 CST Universal time: Mon 2017-03-27 12:14:15 UTC RTC time: Mon 2017-03-27 12:14:15 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a |
查看所有时区timedatectl list-timezones
更改成上海时区timedatectl set-timezone Asia/Shanghai
设置NTP开启timedatectl set-ntp yes
设置NTP关闭timedatectl set-ntp no
timedatectl命令也可以设置时间和日期
设置日期格式timedatectl set-time YYYY-MM-DD
设置时间格式timedatectl set-time HH:MM:SS