问题现象
pmon下设置rtc时间后,在系统下通过date看时间,相差了8小时。
分析过程:
排查内核
内核获取时间的打印信息如下:
[ 3.745377] ls2x-rtc LOON0001:00: setting system clock to 2000-01-01 00:00:19 UTC (946684819)
内核驱动打印的当前系统时间与pmon中的实时时钟时间一致。
小结论:RTC时钟没问题,内核获取的时间也没问题。
排查系统:
1. 查看系统时间信息:
[root@flower pmon-loongarch]# date //系统时间按照CST显示
2022年 11月 15日 星期二 09:58:06 CST
[root@flower pmon-loongarch]# timedatectl
Local time: 二 2022-11-15 09:57:45 CST
Universal time: 二 2022-11-15 01:57:45 UTC
RTC time: 二 2022-11-15 01:57:41
Time zone: Asia/Shanghai (CST, +0800)
Network time on: no
NTP synchronized: no
RTC in local TZ: no
系统下按照CST时间标准显示的。
不同时区UTC/CST标准的时间区别:
UTC:Coordinated Universal Time, 世界协调时间:标准时间,也就是零时区时间。
CST:(China Shanghai Time)是中国标准时间,也叫东八区时间
CST时间=UTC + 8小时。
系统下打印时间= 内核时间+8小时;
因此系统下的系统时钟与RTC实时时钟不一致的原因是:系统时钟与内核获取的RTC时钟所采用的时区标准不同。
解决方法:
修改系统配置,重设系统时区。
在系统文件 /etc/profile 中增加一行配置 export TZ='CST-8'
在命令行source /etc/profile即可。