如何在CentOS7中修改时区和时间

如何在CentOS7中修改时区和时间

  1. 检查当前时区

    [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 ~]# 

  2. 修改时区

    [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 ~]# 

  3. 设置本地硬件时钟

    将硬件时钟设置为系统时钟所在时区的本地时间
    [root@localhost ~]# timedatectl set-local-rtc 1
    将硬件时钟设置为协调世界时(UTC)
    [root@localhost ~]# timedatectl set-local-rtc 0
  4. 手动设置时间和日期

    ##### 取消网络时间同步
    [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 ~]# 

  5. 同步网络时间

    [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 ~]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值