Setting your hardware clock with a new date and time

The Linux system clock runs seperate from the actual clock hardware on the motherboard. Some programs may directly read from the hardware clock instead of the system clock which could lead to trouble. Here is how you can set and sync them.

First to set the hardware clock, you use the date command. date tries to be really intelligent about the date strings you feed it. The following was sufficient to set the date on my machine:

date --set "12:24am Dec 14,2003"

Once you set your system clock the only thing you have to worry about is what happens when you reboot. That is where the hardware clock comes in. It keeps track of the time when your machine is turned off. Your OS will pull the time from the hardware clock when it boots up. You can sink to/from the hardware clock at will with the commands below:

To set the hardware to match the system clock.

hwclock --systohc

To set the system clock to match the hardware clock.

hwclock --hctosys

Note:Thanks to Daniel Farinha for pointing out that the original article had –systohc and –hctosys backwards.

Leave a Reply

Your email address will not be published. Required fields are marked *