≡ Menu

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

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

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


Tue Jul 24 20:12:01 PDT 2007

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


Wed Jul 25 08:46:12 IST 2007

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


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

Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 4 comments… add one }
  • Dracie April 9, 2009, 5:55 am

    why would you need to export it? Bash is a line by line shell interpreter, so you can just put the TZ variable before the program date. Like this: TZ=America/New_York date. This is a better solution if you just need to check the time difference real quick.

    If you are living in a different time zone in awhile just change your timezone in /etc/rc.conf or whichever file your *NIX distribution configures this sort of thing.

    The only time i had to export this variable is on my account on a shell server. It is based in Germany and I live in usa so I just had to put export TZ=America/Chicago in my .bashrc.

    Thanks, and have a good one

  • Vijay April 2, 2012, 1:09 pm

    use this
    $ TZ=IST date
    no need to export or reset the TZ variable

  • Frank September 6, 2012, 9:55 am

    You need to export it because date is not a bash command, it is a separate process that is being forked. Exporting a variable means making it available for forked processes (child processes).

    If it works in your shell without exporting it, it means that your shell provides the date functionality directly without calling /bin/date.

  • h4xp3t December 4, 2013, 2:06 pm

    @Frank: No, the Bourne family of shells specifically allow you to set an environment variable for a child process using the syntax VAR=value cmd — the value of VAR will be available to cmd, and persist while it executes, but no longer.

Security: Are you a robot or human?

Leave a Comment

   Tagged with: , , , , , , , ,