Setting Linux Time

Programs for working with time and date are:

  • clock - This is a soft link to  hwclock. 
  • date(1) - Print or set the system  date and time. 
  • hwclock(8) - Sets the hardware  clock based on values entered on the command line. 
  • setclock(8) - Sets the BIOS  hardware clock based on the time and setup of the system clock. 
  • timeconfig(8) - A program used to  configure the system configuration file "/etc/sysconfig/clock" which includes the type of clock  and timezone. 

An Example:

While logged in as root do the following: 

  1. Type "date". 
  2. You should see some variation  of" 

"Wed Nov 24, 9:29:17 EST 1999" 

  1. To change the time type(as an example): 

#date 030613252012
 03=March
 06=Day
 13=Hour
 25=Min
 2012=Year

The program setclock will set your hardware clock based on your system configuration parameters including whether or not your clock is set to universal time. 

The "clock -w" command assumes your hardware clock is set to local time. If it is set for universal time you will want to type "clock -wu" rather than the "clock -w" in the line above. If you use the wrong option the time will be set incorrectly and you will need to do it again. 

On a Redhat system, you can use the program "linuxconf" as root and page down to the next to the last line in the menu which is "date & time". Select it and see if the box named "universal format(GMT)", next to "Store date in CMOS", is checked. If is is not, you may save your time by typing "clock -w". If it is checked use "clock -wu". 

Note: There is a man page for date that you can use to learn more. Type "man date". You do not want to make any more changes to time and especially to the date than necessary, especially while the system is running, since this can trigger the "cron" daemon to perform various time related system tasks. 

An alternate method to set time is. 
hwclock --set --date "2/24/2000" If you are using local time
hwclock --set --date "2/24/2000" -utcIf you are using universal time 

In the rc.sysinit startup script, this program is used with the options -adjust and -hctosys to adjust the hardware clock for drift, and set the system time to the hardware clock at the time of reboot. 

On Redhat systems, there is a configuration program called "timeconfig" which can be used to configure the system configuration file /etc/sysconfig/clock and /etc/localtime. This program will use a graphical interface to let the user set the timezone and whether UTC time is used. 

 

Another Option:

 See below for an example setting the system time to July, 21 2008 @ 1300

 [root@server /root]# date 072113002008
 Mon Jul 21 13:00:00 EDT 2008
 [root@server /root]# hwclock --utc --systohc
 [root@server /root]#


 The hwclock command then syncs the system and hardware clock. You want to be sure that you set the time correctly using date, before syncing.