如何在CentOS7中修改时区和时间
-
检查当前时区
[root@localhost ~]# timedatectl Local time: Sun 2023-08-06 17:33:10 CST Universal time: Sun 2023-08-06 09:33:10 UTC RTC time: Sun 2023-08-06 17:33:10 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: yes DST active: n/a Warning: The system is configured to read the RTC time in the local time zone. This mode can not be fully supported. It will create various problems with time zone changes and daylight saving time adjustments. The RTC time is never updated, it relies on external facilities to maintain it. If at all possible, use RTC in UTC by calling 'timedatectl set-local-rtc 0'. [root@localhost ~]#
-
修改时区
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai [root@localhost ~]# timedatectl Local time: Sun 2023-08-06 17:34:51 CST Universal time: Sun 2023-08-06 09:34:51 UTC RTC time: Sun 2023-08-06 17:34:51 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: yes DST active: n/a Warning: The system is configured to read the RTC time in the local time zone. This mode can not be fully supported. It will create various problems with time zone changes and daylight saving time adjustments. The RTC time is never updated, it relies on external facilities to maintain it. If at all possible, use RTC in UTC by calling 'timedatectl set-local-rtc 0'. [root@localhost ~]#
-
设置本地硬件时钟
将硬件时钟设置为系统时钟所在时区的本地时间
[root@localhost ~]# timedatectl set-local-rtc 1
将硬件时钟设置为协调世界时(UTC)
[root@localhost ~]# timedatectl set-local-rtc 0
-
手动设置时间和日期
##### 取消网络时间同步 [root@localhost ~]# timedatectl set-time "2021-12-31 12:12:12" Failed to set time: Automatic time synchronization is enabled [root@localhost ~]# timedatectl set-ntp false ##### 手动设置日期和时间 [root@localhost ~]# timedatectl set-time "2021-12-31 12:12:12" [root@localhost ~]# timedatectl Local time: Fri 2021-12-31 12:12:29 CST Universal time: Fri 2021-12-31 04:12:29 UTC RTC time: Fri 2021-12-31 04:12:30 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: n/a [root@localhost ~]#
-
同步网络时间
[root@localhost ~]# timedatectl set-ntp true [root@localhost ~]# systemctl restart ntpd [root@localhost ~]# timedatectl Local time: Sun 2023-08-06 17:44:11 CST Universal time: Sun 2023-08-06 09:44:11 UTC RTC time: Fri 2021-12-31 04:15:21 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a [root@localhost ~]#