This article describes the steps to change the system and hardware clock on linux without the need to use ntp. The steps described in this article are performed on CentOS 6.
The best way to get started is to find out the times which the system is currently using. One Linux and most operating systems we have two time settings:
To check the hardware time the following command can be issued:
hwclock
My hardware clock is set to 04:37 AM AST.
To check the system clock we can issue the following command:
date
My system clock is set to 04:40 AM AST, the same as the hardware clock.
To change the system clock we simply remove the /etc/localtime file and then recreate the file using a symbolic link to a timezone file which comes pre-packed on the system.
First remove the localtime file with the following:
rm -rf /etc/localtime
Now recreate the file as a symbolic link from the timezone file of your choice, in my case I choose "Europe/London":
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
You can find more about the different timezones here.
The next thing to do is to change the zone information inside of the clock config file to represent the timezone you used above:
nano /etc/sysconfig/clock
or
vi /etc/sysconfig/clock
Finally you can run the following command to make the hardware clock sync with the system clock:
hwclock --systohc --localtime
You can now check the changes by issuing the following commands again:
hwclock
date
They should now both match. This will also change the Timezone the machine is running as well as the date when required!