Centos系统时间和时区配置

一、时间配置(临时配置和永久配置)
a.临时配置:reboot后失效

[root@tmpt01 ~]# date -s "2018-12-20 16:34:11"
Thu Dec 20 16:34:11 CST 2018
[root@tmpt01 ~]# 
[root@tmpt01 ~]# 
[root@tmpt01 ~]# date
Thu Dec 20 16:34:13 CST 2018

b.永久配置
eg:实例

[root@tmpt01 ~]# hwclock --set --date "2018-12-20 16:37:30"
[root@tmpt01 ~]# hwclock --hctosys                  #系统时间和硬件中的时间计数器同步时间。
[root@tmpt01 ~]# clock -w                                #保存配置
[root@tmpt01 ~]# 
[root@tmpt01 ~]# 
[root@tmpt01 ~]# date               
Thu Dec 20 16:38:01 CST 2018
[root@tmpt01 ~]# hwclock --show
Thu 20 Dec 2018 04:38:11 PM CST  -0.282644 seconds

为什么要使用clock --set 配置

[root@tmpt01 ~]# date -s "2018-12-20 16:41:00"
Thu Dec 20 16:41:00 CST 2018
[root@tmpt01 ~]# 
[root@tmpt01 ~]# hwclock --show                 #实际硬件时间没有保存,如果reboot机器那么重启后系统时间为硬件的中的时间(所以修改系统最好用hwclock --set的方法)
Thu 20 Dec 2018 04:39:39 PM CST  -0.892401 seconds
[root@tmpt01 ~]# 

二、Centos时区配置:
查看系统的时区

[root@tmpt01 ~]$ timedatectl 
      Local time: Thu 2018-12-20 16:27:56 CST
  Universal time: Thu 2018-12-20 08:27:56 UTC
        RTC time: Thu 2018-12-20 16:27:56
       *Time zone: Asia/Shanghai (CST, +0800)*
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a

修改时区(修改后永久生效,reboot后也生效)

[root@tmpt01 ~]# timedatectl set-timezone Asia/Dubai   #设置为Dubai时区
[root@tmpt01 ~]# timedatectl 
      Local time: Thu 2018-12-20 12:50:03 GST
  Universal time: Thu 2018-12-20 08:50:03 UTC
        RTC time: Thu 2018-12-20 12:50:04
       Time zone: Asia/Dubai (GST, +0400)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a
[root@tmpt01 ~]# 
[root@tmpt01 ~]# timedatectl set-timezone Asia/Shanghai      # #设置为Shanghai时区
[root@tmpt01 ~]# 
[root@tmpt01 ~]# timedatectl 
      Local time: Thu 2018-12-20 16:50:17 CST
  Universal time: Thu 2018-12-20 08:50:17 UTC
        RTC time: Thu 2018-12-20 16:50:17
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a

猜你喜欢

转载自blog.csdn.net/u013908944/article/details/85127084