每次重启后,日期、时钟都会显示错误

每次重启后,日期、时钟都会显示错误

编辑问题以更好地反映情况。(我的时钟和日期显示不正确)

我使用的是 +GMT 8 时间,并且我已通过以下方式将时钟设置为本地时区

rm /etc/adjtime
system-config-date -- to set the correct date/time
ln -s /usr/share/zoneinfo/Asia/Singapore localtime
hwclock --systohc --localtime

请检查我的配置

[root@sjoam2 etc]# date
Sun Aug  2 03:24:59 SGT 2015

[root@sjoam2 etc]# hwclock --debug
hwclock from util-linux-ng 2.17.2
Using /dev interface to clock.
Last drift adjustment done at 1438457074 seconds after 1969
Last calibration done at 1438457074 seconds after 1969
Hardware clock is on local time
Assuming hardware clock is kept in local time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2015/08/02 03:25:16
Hw clock time : 2015/08/02 03:25:16 = 1438457116 seconds since 1969
Sun 02 Aug 2015 03:25:16 AM SGT  -0.672466 seconds


[root@sjoam2 etc]# cat /etc/adjtime 
0.000000 1438457074 0.000000
1438457074
LOCAL

一切似乎都很好。日期和时钟显示的时间正确,直到我重启。重启后,日期又增加了 8 小时,尽管我已经指定时钟为本地时间。

[root@sjoam2 ~]# date
Sun Aug  2 11:30:06 SGT 2015 **-- why +8 hours ? i have specified hwclock in localtime**

[root@sjoam2 ~]# hwclock --debug
hwclock from util-linux-ng 2.17.2
Using /dev interface to clock.
Last drift adjustment done at 1438457074 seconds after 1969
Last calibration done at 1438457074 seconds after 1969
Hardware clock is on local time
Assuming hardware clock is kept in local time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2015/08/02 03:30:09
**Hw clock time : 2015/08/02 03:30:09 = 1438457409 seconds since 1969
Sun 02 Aug 2015 03:30:09 AM SGT  -0.626865 seconds  -- still showing the correct timing for hwclock**

有哪位大师可以对此作出解释吗?

问候,Noob

答案1

首先备份本地时间文件。

sudo mv /etc/localtime /etc/localtime.bak

然后,

sudo ln -s /usr/share/zoneinfo/Country/City /etc/localtime

替换您居住的国家和城市。保存并重新启动。有关更多信息,请关注这两个线程。更改时区, 我认为为您提供一些其他详细信息。

答案2

如果新加坡时间格林威治标准时间/世界标准时间时间加上 8 小时,当您重新启动时,您将提前 16 小时,您的系统似乎对偏移进行了两次补偿。

在 CentOS 7 系统上,我遇到了时间差几个小时的问题直到我使用了 timedatectl 命令。例如:

timedatectl set-timezone Asia/Singapore

“set-timezone”选项执行以下操作:

set-timezone [TIMEZONE]
           Set the system time zone to the specified value. Available
           timezones can be listed with list-timezones. If the RTC is
           configured to be in the local time, this will also update the RTC
           time. This call will alter the /etc/localtime symlink. See
           localtime(5) for more information.

尽管该系统上的硬件时钟使用的是 UTC 时间。例如,我看到以下内容:

# hwclock --debug
hwclock from util-linux 2.23.2
Using /dev interface to clock.
Last drift adjustment done at 0 seconds after 1969
Last calibration done at 0 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2015/08/01 20:54:34
Hw clock time : 2015/08/01 20:54:34 = 1438462474 seconds since 1969
Sat 01 Aug 2015 04:54:34 PM EDT  -0.904866 seconds

上述命令的最后一行hwclock --debug显示了该系统在相关时区的正确本地时间。

在该系统上,我看到 /etc/localtime 以下内容:

# ls -l /etc/localtime lrwxrwxrwx. 1 root root 38 Oct 5 2014 /etc/localtime -> ../usr/share/zoneinfo/America/New_York

如果你输入ls -l /etc/localtime你仍然会看到它指向/usr/share/zoneinfo/Asia/Singapore

相关内容