Setting the date and time in Linux
Author: Nediam <javier@nediam.com.mx>
Publication date: 2005-12-20
Setting the date and time manually is advisable only if the applications that are running on the server and the server itself don't need to have the exact time, maybe it can be a difference of +-1 second with the real time. If they require 100% of accuracy in the time, then the server should synchronize
(probable using the NTP protocol) with a server that offer this service. For more information about this, check
this page.
- Search on the Internet a page that displays the real time. For example, the page that I used was: http://www.timeanddate.com/worldclock/. In the main page I search and clicked on the "Mexico City" link and this way I obtained the real time for my zone (remember that this method doesn't assure us a 100% of accuracy, but a very near value of the real time).
- Using the command date manually set the system clock (this is the clock that the Operating System always uses):
SERVER:~# date
Wed Dec 7 01:29:18 CST 2005
SERVER:~# date --set="Wed Dec 7 2005 09:14:00 CDT"
SERVER:~# date
Wed Dec 7 09:14:02 CDT 2005
- Synchronize the machine clock (also called RTC, hardware clock, BIOS or CMOS clock) using the system clock:
SERVER:~# hwclock --systohc
- If what is wanted is to manually set the machine clock, although I don't see why one would want to do this, then do it using the
hwclock command:
SERVER:~# hwclock
Wed Dec 7 01:32:30 2005 -0.601889 seconds
SERVER:~# hwclock --set --date "Wed Dec 7 2005 09:17:00"
SERVER:~# hwclock
Wed Dec 7 09:17:03 2005 -0.154317 seconds
Notes:
- Every time that a computer starts in *nix, the system clock is initialized using the hardware clock. Starting from there, the only clock that
is used is the system clock (of course there can be exceptions, since the RTC one can be accesed through /dev/rtc). The system clock is a timer
that counts the seconds elapsed since 00:00 hrs. of January 1st 1970 (UTC).
- When a machine reboots or halts, the hardware clock is updated using the system clock as reference. This is commonly configured in the init
script hwclock.sh.
- If the 11 minute mode is activated, then the hardware clock will be updated every 11 minutes using the system clock as reference.
References:
- hwclock man page - http://www.die.net/doc/linux/man/man8/hwclock.8.html
- date man page - http://www.die.net/doc/linux/man/man1/date.1.html
- Bover, Daniel P., Cesati Marco. Undertanding the Linux Kernel Chapter 6: Timing measurements. O'reilly. ISBN 0596002130.
- The Clock Mini-HOWTO. Chapter 2 -http://www.tldp.org/HOWTO/Clock-2.html
- Introduction to Linux Systems Administration. Chapter 12 - http://infocom.cqu.edu.au/Units/aut99/85321/Resources/Print_Resources/Textbook/chap12/
The latest version of this document is available at:
http://nediam.com.mx/en/tips/date_time.php



