Sync hardware clock with current system date and time

There are two main clocks in a Linux system:

The Hardware Clock: This is a clock that runs independently of any control program running in the CPU and even when the machine is powered off.

The System Time: This is the time kept by a clock inside the Linux kernel and driven by a timer interrupt. It has meaning only while Linux is running on the machine.

Often-times, it happens that when you reboot, your clock does not reflect the correct date and time. You may be forgetting to sync the hardware clock with the current system time. Here is how:

First check and set the current system date and time.

# date
# date -s 'Wed May 28 11:35:00 EST 2003'

Then sync your hardware clock with the system time.

# hwclock --show
# hwclock --systohc

man date and hwclock for more info...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

thanks!!

thank for your post :)

setting time with ntpdate

You can also set the date using ntpdate.

# ntpdate pool.ntp.org

If it complains about socket in use, then stop ntpd and run the ntpdate again.

I also have a script in daily cron to sync the date to hardware clock, just in case server needs to be hard reset.

In /etc/crontab :

# sync hardware clock
0 2 * * * root /sbin/hwclock --systohc >> /var/log/messages

Post new comment

  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
Comment