Server clocks has a tendency to drift, so to ensure correct date, time and zone once and for all is a good thing.
Setting the date
sudo date +%Y%m%d -s "20081128"
Setting the time
sudo date +%T -s "08:23:00"
Setting the timezone
This is done by making /etc/localtime into a symbolic link that goes to the timezone the server is to use.
sudo ln -sf /usr/share/zoneinfo/your/zone /etc/localtime
Setting UTC or local time
Change the content of the file /etc/sysconfig/clock
to “UTC=true” or “UTC=false” (in norway it’s true).
Setting the hardware clock
Synchronizes the hw clock and system clock. Only add the “–utc” parameter if you are using UTC:
/sbin/hwclock --systohc --utc
Regurlarly synchronize the clock toward Network Time Protocol
This is done by adding this to crontab (ensure that the path to rdate is correct beforehand):
# update time with NTP server
0 3, 9, 15, 21 * * * /usr/sbin/rdate 128. 2. 136. 71 | logger -t NTP
2 Responses to Setting date and time in linux