nixCraft Poll

Topics

Linux / UNIX: display time of different time zones using TZ environment variable

Posted by Vivek Gite [Last updated: July 25, 2007]

Let us say you need to display time for different zones or cities. Sure you can use The World Clock - Time Zones located here. If you need a different time zone at a shell prompt or script use old good date command.

Different timezones can be displayed by changing the TZ environment variable.

TZ Specifies the timezone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used by Linux/UNIX computer.

Display current date and timezone

$ date
Output:

Tue Jul 24 22:05:54 CDT 2007

Display time of different timezones using the date command and TZ variable

Set timezone to PDT:
$ export TZ=America/Los_Angeles
$ date

Output:

Tue Jul 24 20:12:01 PDT 2007

Or set timezone to IST:
$ export TZ=Asia/Calcutta
$ date

Output:

Wed Jul 25 08:46:12 IST 2007

Remove the TZ variable with unset command:
$ unset TZ
$ date

Output:

Tue Jul 24 22:17:31 CDT 2007

Read date,bash,unset command man page for more information. Hope this small tip will save your time and see a different time zone.

Related: Howto: Redhat enterprise Linux / CentOS setup DST - Daylight Saving Time

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.