如何在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 ~]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CentOS 7上修改时间时区,可以按照以下步骤进行操作: 1. 首先,使用以下命令设置时区: ``` sudo timedatectl set-timezone 'Asia/Shanghai' ``` 或者 ``` echo "Asia/Shanghai" > /etc/timezone ``` 2. 然后,使用以下命令设置系统时间: ``` rm -rf /etc/localtime ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ``` 3. 如果需要使用NTP服务进行时间同步,可以按照以下步骤进行操作: 3.1 安装NTP服务: ``` yum -y install ntp ``` 3.2 启动NTP服务: ``` systemctl start ntpd systemctl enable ntpd ``` 3.3 查看NTP服务状态: ``` systemctl status ntpd ``` 4. 如果需要重启时间同步服务,可以使用以下命令: ``` systemctl restart chronyd ``` 5. 检查时间同步状态: ``` chronyc sources ``` 6. 如果需要将硬件时间同步到系统时间,可以使用以下命令: ``` hwclock -w ``` 7. 最后,使用以下命令查看当前时间是否正确: ``` date ``` 请注意,以上步骤的命令需要以root权限或使用sudo来执行。修改时间时区可能会对系统产生影响,请谨慎操作。 #### 引用[.reference_title] - *1* *3* [centos7设置时区时间+时间同步的三种方式](https://blog.csdn.net/Liu__sir__/article/details/130635044)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Centos7 修改系统时区(显示北京时间)](https://blog.csdn.net/ling1998/article/details/123696598)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值