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.

  1. 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).
  2. 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
  3. Synchronize the machine clock (also called RTC, hardware clock, BIOS or CMOS clock) using the system clock:
    SERVER:~# hwclock --systohc
  4. 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:


References:


The latest version of this document is available at: http://nediam.com.mx/en/tips/date_time.php

<< 0 comments >>



TOP