Setting Date and Time on Linux

 

Setting Date and Time on Linux


 

Contents

  1. Overview
  2. Setting your timezone
  3. Setting UTC or local time
  4. Setting the system clock
  5. Setting the hardware clock

 

See Also

  1. Time Servers
  2. Clock Mini-HOWTO

 


 

Overview

Computers have two timepieces:

  1. A hardware, battery-backed clock that is always running
  2. The OS or system clock

The hardware clock is used to set the system clock when the OS boots. The system clock is the one used to keep track of time. The hardware clock can be kept in UTC/GMT time or local time.

 


 

Setting your timezone

The timezone under Linux is set by a symbolic link from /etc/localtime to a file in the /usr/share/zoneinfo directory that corresponds to your timezone:

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

Look under /usr/share/zoneinfo to see what timezones are available.

 


 

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.

UTC=value Set clock to Universal Time. True or False
ARC=value "true" sets the ARC console 42-year time offset. Any other value sets normal UNIX epoch is assumed (Alpha-based systems).
ZONE=filename Indicates which timezone file under /usr/share/zoneinfo that /etc/localtime is a copy of. For example: ZONE="America/New York"

 


 

Setting the system clock

To set the system clock under Linux, use the date command.

To set the current time and date to August 31, 15:42pm, one would type date 08311542

 


 

Setting the hardware clock

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''

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''


  Home