Linux Timezones

From Public wiki of Kevin P. Inscoe
Jump to navigation Jump to search

Timezones in Linux

See also http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

The timezone files are stored in /usr/share/zoneinfo these files are binary and compiled by zic command. EST5EDT is a timezone file mapped to US Eastern time (daylights saving included). The US is currently in Daylight savings hence the date command output but the zonefile maps both changes.

The system clock itself the timezone in RHEL 6 is set using the file /etc/sysconfig/clock.

The hwclock command will show the pseudo hardware clock and its timezone.

$ sudo hwclock --show 
Fri 09 Sep 2016 03:33:17 PM EDT  -0.866303 seconds

The timezone users see when they login in by default is controlled by file /etc/localtime. This is not a text file but a timezone file itself. It may either be symlinked to one of the timezone files mentioned above or it may be copied from a zonefile. If it is copied you can view what the timezone is inside by using zdump.

$ sudo zdump  /etc/localtime
/etc/localtime  Tue Apr  5 13:07:13 2016 EDT

This can be overridden on a login or shell basis by the TZ shell variable.

$ ls -l /usr/share/zoneinfo/Europe/Dublin
-rw-r--r-- 2 root root 3533 Jun 16  2015 /usr/share/zoneinfo/Europe/Dublin
$ TZ='Europe/Dublin'
$ export TZ
$ date
Tue Apr  5 18:13:58 IST 2016
$ unset TZ
$ date    
Tue Apr  5 13:14:06 EDT 2016

The clock source for AWS is Xen and you can see this in the file /sys/devices/system/clocksource/clocksource0/current_clocksource. AWS instances drift pretty badly so we use NTP to correct them. That config is in /etc/ntp.conf. We reply on the AWS dhcp server to fill this file in unless overridden. On RHEL 6 they use the Redhat NTP pool servers.

ntp time service are normally started on boot - See further reading at http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

$ sudo yum install ntp
$ sudo chkconfig ntpd on
$ sudo service ntpd start

cron jobs

For cron jobs to fire at the time zone you are concerned with it (without as lot of hacking) will follow the system time zone and ignore the TZ variable. So generally speaking the only reason I change the system zone is for that reason.

Standard time zone for HMH

See also http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

Open the /etc/sysconfig/clock file with your favorite text editor (such as vim or nano). You need to use sudo with your editor command because /etc/sysconfig/clock is owned by root.

This file may be empty which means the system is UTC by default. If the file is not empty then Locate the ZONE entry, and change it to the time zone file (omitting the /usr/share/zoneinfo section of the path). For example, to change to the Boston, US time time zone, change the ZONE entry to the following. If the file is empty simply create the line below.

ZONE="EST5EDT"

or

ZONE="America/New_York"

Both are geo-politically equivalent.

The modify the /etc/localtime file:

$ sudo ln -sf /usr/share/zoneinfo/EST5EDT /etc/localtime

hwclock should now show EST/EDT time vs UTC time.

$ sudo hwclock --show 
Fri 09 Sep 2016 04:00:09 PM EDT  -0.131201 seconds