Skip to main content

Manually setting the system date (and hardware clock) in Ubuntu Linux

I typed date on my Ubuntu server tonight at 23:06, this is what it reported from the system clock:
Tue May 29 22:56:41 BST 2007
I decided to also check the hardware clock (the one maintained by the CMOS/BIOS) by running hwclock:
Tue 29 May 2007 23:04:46 BST  -0.258052 seconds
Looks like I need to bring my server 'up to date'!

To update the system clock use the date command but also pass the date you want the clock set to (you need to be root/sudo to do this):
date 05292310
This reads as: "set the system date to the 5th month, the 29th day, the 11th hour (pm) and ten minutes". Remember the date format is American so month first then the day!

That sorted the system clock out, so I turned my attention to the hardware clock. This can be easily synchronised with the now correct system clock with the systohc option:
hwclock --systohc
Below is the hardware clock's date before and after the update compared to the system clock:
$ date
Tue May 29 23:14:12 BST 2007

$ hwclock
Tue 29 May 2007 23:13:02 BST -0.504456 seconds

$ sudo hwclock --systohc

$ hwclock
Tue 29 May 2007 23:14:27 BST -0.679613 seconds
Now both clocks are back in sync with the real time and each other. Of course this can also be solved with ntp but that's an article for some time in the future! :)

Note: for a more detailed explanation of clocks, locales and timezones please read LinuxSA's "Linux Tips - Linux, Clocks, and Time"

Technorati Tags: , , , , , , ,

Comments

Anonymous said…
Nice article.

You can also change time by changing timezone.
using command below.
ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime

sj at himalayansouvenirs.com
Andrew Beacock said…
Cheers for the tip SJ!
Lev said…
Thanks! This post helped me get the time right in my server too!