CentOS 7 /RHEL 7: How To Change Hardware Clock Date And Time Using Hwclock
The hardware clock is independent of the current operating system and it runs even when you shutdown the machine. and the system clock is managed by Linu kernel. sometimes it is also called BIOS clock, CMOS clock, RTC. you can use “timedatectl” command to get the RTC time or just run “hwclock” command.
When system startup, the hardware clock will be synchronized to system clock, of cource, if you enable the NTP synchronized, system will synchronize the local system time from a remote NTP server.
From manual page of hwclock:
The System Time is the time that matters. The Hardware Clock’s basic purpose in a Linux system is to keep time
When Linux is not running. You initialize the System Time to the time from the Hardware Clock when Linux starts up, and then never use the Hardware Clock again. Note that in DOS, for which ISA was designed, the Hardware Clock is the only real time clock
In this post, you will see how to:
#1 Display the current Hardware clock
#2 Set the hardware time
#3 Sync system time to hardware clock
#4 sync hardware clock to system time
CentOS 7 Display The Current Hardware Clock
If you want to check the current hardware clock date and time, just simply type “hwclock” command. This is the same date and time that you see from the BIOS Clock. Also you can use option “-r” or “–show” options to print the date and time on standard output. If you want to keep your hardware clock in coordinated Universal Time, need to use “–utc” option.
[root@devops Desktop]# hwclock -r Mon 08 Dec 2018 08:24:29 PM CET -0.510911 seconds [root@devops Desktop]# hwclock --show Mon 08 Dec 2018 08:24:32 PM CET -0.275081 seconds [root@devops Desktop]# hwclock Mon 08 Dec 2018 08:24:39 PM CET -0.894427 seconds [root@devops Desktop]# hwclock --utc Mon 08 Dec 2018 08:24:46 PM CET -0.431321 seconds
CentOS 7 Set The Hardware Clock
You can manually set the hardware clock using the “–set” and “–date” option, for example, to set the hardware clock date and time to “12/09/2018 09:20:19” or “Mon 08 Dec 2018 09:20:19”:
[root@devops Desktop]# hwclock --set --date "12/09/2018 09:20:19" [root@devops Desktop]# hwclock Tue 09 Dec 2018 09:20:22 AM CET -0.566487 seconds [root@devops Desktop]# hwclock --set --date "Mon 08 Dec 2018 09:20:19" [root@devops Desktop]# hwclock Mon 08 Dec 2018 09:20:23 AM CET -0.126009 seconds
CentOS 7 Set The Hardware Clock To The current System Time
If you want to set the hardware clock to the current system time or make sure that your hardware clock are same as the ysstem clock date and time. then you can sync the system time to hardware clock using “–systohc” option or “-w” option.
[root@devops Desktop]# date Tue Dec 9 08:24:32 CET 2014 [root@devops Desktop]# hwclock Mon 08 Dec 2014 09:29:23 AM CET -0.475276 seconds [root@devops Desktop]# hwclock --systohc [root@devops Desktop]# hwclock Tue 09 Dec 2014 08:24:51 AM CET -0.395711 seconds [root@devops Desktop]#
CentOS 7 Set The System Time From The Hardware Clock
You can also set the system time from the hardware clock of your machine using “–hctosys” option.
[root@devops Desktop]# date Tue Dec 9 09:27:55 CET 2014 [root@devops Desktop]# hwclock Tue 09 Dec 2014 08:28:09 AM CET -0.270648 seconds [root@devops Desktop]# hwclock --hctosys [root@devops Desktop]# date Tue Dec 9 08:28:22 CET 2014