nav-left cat-right
cat-right

Linux Time and Clocks

There are two clocks in your computer. The hardware (CMOS) clock runs even when the computer is turned off, and is used when the system starts up and by DOS (if you use DOS). The ordinary system time, shown and set by date, is maintained by the kernel while Linux is running.

You can display the CMOS clock time, or set either clock from the other,
with /sbin/clock (or hwclock).

There are various other programs that can correct either or both clocks for system drift or transfer time across the network. Some of them may already be installed on your system. Try looking for adjtimex (display or set the kernel time variables), Network Time Protocol clients like netdate, getdate, and xntp, or NTP client-server suite like chrony

Setting UTC or local time
**************************
When Linux boots, one of the initialization scripts will run the /sbin/hwclock program to copy the current hardware clock time to the system clock. hwclock will assume the hardware clock is set to local time unless it is run with the –utc switch. Rather than editing the startup script, under Red Hat Linux you should edit the /etc/sysconfig/clock file and change the “UTC” line to either “UTC=true” or “UTC=false” as appropriate.

Setting the hardware clock
**************************
To set the hardware clock, set the system clock first, and then set the hardware clock to the current system clock by typing “/sbin/hwclock –systohc” (or “/sbin/hwclock –systohc –utc” if you are keeping the hardware clock in UTC). To see what the hardware clock is currently set to, run hwclock with no arguments. If the hardware clock is in UTC and you want to see the local equivalent, type “/sbin/hwclock –utc”.

Setting the system clock
**************************
To set the system clock under Linux, use the date command. Type date on command line and follow the same format to modify time and/or date.

$ date
Sun Mar 13 02:32:18 IST 2008

$ date -s "Mar 13 02:32:18 2008"

sets the date to the above one. Here you can omit the Day of Week (which the system knows how to calculate from date) and timezone which is configured independently.

~mohammed

Leave a Reply