HowTo Use The Real Time Clock

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box
Tux.png Applies to Linux

Introduction[edit | edit source]

When running Linux kernel, the system has two timepieces:

  1. the battery-backed RTC that is always running
  2. the system clock maintained by the kernel itself; this clocks lives in the kernel memory space and don’t refer to any hardware device.

Real Time Clock[edit | edit source]

Usually, when Linux boots, the system reads current date and time from the RTC and updates the system clock with the common hwclock Linux application. As an example, let's have a look at the file /etc/rc.sysinit of the network root file system provided by ELDK. The script invokes the hwclock application (line 271) to set up the system clock. From now on, the kernel updates the system clock independently from the external RTC. On the contrary, command date command affects only the system clock. Users who want to modify the hardware RTC must use the utility hwclock with proper options.

Timezone[edit | edit source]

Another important parameter for what concerns the Linux clock is the timezone. Usually the timezone under Linux is set by a symbolic link from /etc/localtime 2 to a file in the /usr/share/zoneinfo directory that describes your timezone. For example, if you are in South Australia, /etc/localtime should be a symlink to /usr/share/zoneinfo/Australia/South. To set this link, you should type:

ln -sf /usr/share/zoneinfo/your/zone /etc/localtime

You should replace your/zone with something like Australia/NSW or Australia/Perth3. When hwclock command is invoked with --hctosys option, it sets the kernel timezone to the value indicated by the link /etc/localtime. Last but not least, note that the time reported by hwclock is also affected by /etc/adjtime file as explained here http://www.die.net/doc/linux/man/man8/hwclock.8.html. Reading of this document is strongly recommended.