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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Dracie Apr 9, 2009 @ 5:55

    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 Apr 2, 2012 @ 13:09

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

  • Frank Sep 6, 2012 @ 9:55

    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 Dec 4, 2013 @ 14:06

    @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.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum