Linux服务器时区问题不对处理方案


问题:
Local time: Fri 2026-06-26 18:26:50 CST Universal time: Fri 2026-06-26 10:26:50 UTC RTC time: Fri 2026-06-26 18:26:50 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: no 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'.




 

现在的状态:

  • 硬件时钟(RTC time):18:26:50

  • 系统本地时间(Local time):18:26:50 CST

  • UTC时间:10:26:50 UTC

问题所在:
硬件时钟里存的是 18:26:50,但正确的北京时间应该是 10:26:50(因为UTC时间10:26:50 + 8小时 = 18:26:50 CST)。

硬件时钟快了8个小时!它存的是CST时间(18:26:50),但系统以为是UTC时间,所以显示时又加了8小时,导致CST变成了18:26:50。

🔧 正确的解决方法

既然硬件时钟(RTC)里存的时间就是错的(快了8小时),我们需要先把硬件时钟改成正确的时间

步骤1:先改回 UTC 模式(避免双重转换)

bash

sudo timedatectl set-local-rtc 0

步骤2:手动设置系统时间为正确的北京时间

当前正确的北京时间应该是 10:26:50(因为UTC显示10:26:50):

bash

sudo date -s "2026-06-26 10:26:50"

步骤3:将正确的系统时间写入硬件时钟(UTC格式)

bash

sudo hwclock --systohc --utc

步骤4:验证

bash

timedatectl status
date

期望输出:

text

Local time: Fri 2026-06-26 10:26:50 CST    ← 正确的北京时间
Universal time: Fri 2026-06-26 02:26:50 UTC ← UTC时间
RTC time: Fri 2026-06-26 02:26:50          ← 硬件时钟存储UTC时间(02:26:50)
Time zone: Asia/Shanghai (CST, +0800)
RTC in local TZ: no                         ← 保持 no(推荐)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值