Linux – date and hwclock not in sync – why

centoscentos6linuxredhatUbuntu

I am on GMT+8 and I set my hwlock to UTC.

[root@sjoam2 ~]# date
Sat Aug  1 16:32:04 SGT 2015
[root@sjoam2 ~]# hwclock --systohc --utc
[root@sjoam2 ~]# hwclock --debug
hwclock from util-linux-ng 2.17.2
Using /dev interface to clock.
Last drift adjustment done at 1438417931 seconds after 1969
Last calibration done at 1438417931 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 08:32:17
Hw clock time : 2015/08/01 08:32:17 = 1438417937 seconds since 1969
Sat 01 Aug 2015 04:32:17 PM SGT  -0.641290 seconds
[root@sjoam2 ~]# 

Seems fine.

hwclock debug is showing 08:32 UTC

— I am not so sure on the last sentence in hwclock –debug
(Sat 01 Aug 2015 04:32:17 PM SGT -0.641290 seconds)
whereby it shows the date in current timezone format (which is +8 hours) – i assume its fine

After reboot

[root@sjoam2 ~]# hwclock --debug
hwclock from util-linux-ng 2.17.2
Using /dev interface to clock.
Last drift adjustment done at 1438417931 seconds after 1969
Last calibration done at 1438417931 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 08:36:45
Hw clock time : 2015/08/01 08:36:45 = 1438418205 seconds since 1969
Sat 01 Aug 2015 04:36:45 PM SGT  -0.782726 seconds
[root@sjoam2 ~]# 

Still seems ok from hwclock –debug output
Hwclock = 08:36

— I am not so sure on the last sentence in hwclock –debug (Sat 01 Aug 2015 04:36:45 PM SGT -0.782726 seconds) whereby it shows the date in current timezone format (which is +8 hours) – i assume its fine

But look at date now

[root@sjoam2 ~]# date
Sun Aug  2 00:40:31 SGT 2015

It is adding another 8 hours to the correct time of the hwclock last output
Sat 01 Aug 2015 04:36:45 PM SGT + 8 more hours, which is adding a total of 16 hours to the UTC timing

How do i prevent that ? Where has my configurations gone wrong.

Best Answer

I synchronized date and hwclock with this command:

$ sudo hwclock --systohc

Above command writes date time to hwclock time.

NOTE: If you want write hwclock time to date time do it:

$ sudo hwclock --hctosys

For test:

$ sudo hwclock --show
$ date

NOTE: You can use hwclock -s instead of hwclock --hctosys and hwclock -w instead of hwclock --systohc.

systohc = system time to hardware time.
hctosys = hardware time to system time.