Switching timezones

Timezones can be set by setting the TZ environment variable.

A list of all timezones supported by the OS can be found in the zoneinfo directory. This directory is located at /usr/lib/zoneinfo on many UNIX distributions. On Linux I found it to be in /usr/share/zoneinfo

“locate zoneinfo” can help determine where the zoneinfo directory is

Lets say I wish to write a script that shows me the time in Los Angeles (PDT) when my system clock is set at Mumbai (IST) and shows me the IST when system clock is set at PDT.

#!/bin/sh

if [ TZ == “Asia/Kolkata” ]

then

TZ=America/Los_Angeles

else

TZ=Asia/Kolkata

fi

export TZ

echo `date`

>>Note that this script does not set the environment permanently….(it is a child process called by the shell…children cannot set their parents’ environment variables…they only inherit a copy of those variables.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: