How to update time zone in Linux?

Some times it is required to update our timezone when we move our machines(VMs) from one location to other. Recently I came across a situation where I want to move my machine time zone from IST to Sydney time zone. In this post we will see on how to set time zone in a Linux machine.

Check which time zone you are in by executing date command.

Example:

	[root@node1 ssl]# date
Fri Nov 21 03:18:49 IST 2014

In Linux timezone data is taken from /etc/localtime which is linked to one of the file located in /usr/share/zoneinfo/*. So we have to first remove this file and then link this file to one of the timezone files located in /usr/share/zoneinfo folder. As my requirement is to set my time zone as Sydney, I will link my /etc/localtime with Sydney file as shown below.

Step1: Remove /etc/localtime

Example:

	[root@node1 ssl]# ls -l /etc/localtime 
-rw-r--r--. 3 root root 265 Nov 12  2010 /etc/localtime
[root@node1 ssl]# unlink /etc/localtime 

Step2: Now check where is Sydney related file located in /usr/share/zoneinfo folder.

	Example:
[root@node1 ssl]# ls -l /usr/share/zoneinfo/
Africa/      Atlantic/    Chile/       Eire         Factory      GMT-0        Iceland      Jamaica      Mexico/      NZ           posix/       ROC          Universal    zone.tab     
America/     Australia/   CST6CDT      EST          GB           GMT+0        Indian/      Japan        Mideast/     NZ-CHAT      posixrules   ROK          US/          Zulu         
Antarctica/  Brazil/      Cuba         EST5EDT      GB-Eire      Greenwich    Iran         Kwajalein    MST          Pacific/     PRC          Singapore    UTC          
Arctic/      Canada/      EET          Etc/         GMT          Hongkong     iso3166.tab  Libya        MST7MDT      Poland       PST8PDT      Turkey       WET          
Asia/        CET          Egypt        Europe/      GMT0         HST          Israel       MET          Navajo       Portugal     right/       UCT          W-SU         

 

[root@node1 ssl]# ls -l /usr/share/zoneinfo/Australia/
ACT          Brisbane     Canberra     Darwin       Hobart       Lindeman     Melbourne    NSW          Queensland   Sydney       Victoria     Yancowinna   
Adelaide     Broken_Hill  Currie       Eucla        LHI          Lord_Howe    North        Perth        South        Tasmania     West         

Step3: Once you find Sydney file just link to our /etc/localtime file as shown below

Example:

	[root@node1 ssl]# ln -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime

Step4: Once the above step is done successfully try check if date is update with right timezone or not

	Example:
[root@node1 ssl]# date
Fri Nov 21 08:53:03 EST 2014
The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.