How to set TZ environment variable in Linux / Unix

See all UNIX related articles/faq
What is the correct format for a TZ (time zone) environment variable for use with the Linux or UNIX operating system?

The format required for the TZ variable is specified by the operating system using system wide or user specific shell profile file. You can set the TZ and make this change permanent for yourself by appending the line to the file .profile in your home directory; then log out and log in again.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix terminal
Category User Environment
OS compatibility BSD Linux macOS Unix
Est. reading time 3 minutes
Advertisement

How to set TZ environment variable in Linux / Unix

In this example, I’m setting my TZ variable (timezone) to Indian standard time (IST) as follows using the export command:

TZ='Asia/Kolkata'
export TZ

Example

To display your current date & time use the date command. For example:
$ date
Sample outputs:

Sat Jan 29 06:21:38 EST 2011

The timezone is set to EST. To view exact details, enter:
$ cat /etc/sysconfig/clock
Sample outputs:

ZONE="America/New_York"
UTC=true
ARC=false

To set your timezone to IST at the CLI, enter:

TZ='Asia/Kolkata'
export TZ

OR

export TZ='Asia/Kolkata'

To display date & time according to the TZ variable, enter:
$ date
Sample outputs:

Sat Jan 29 16:54:46 IST 2011

How Do I Make the TZ Changes Permanent?

Edit the $HOME/.profile or $HOME/.bash_profile appending the line and then log out and log in again:

TZ='Asia/Kolkata'; export TZ

How Do I Set the Time Zone Using the Posix TZ Format?

You can use the following syntax:

TZ='POSIX-fomat'
export TZ

In this example, set TZ to GST-10 i.e. set it to a zone named GST that is 10 hours ahead (east) of UTC:

TZ='GST-10'
export TZ
date

How Do I Find Out and View the Installed Timezone under Linux or UNIX?

Many UNIX like operating systems ships with the tzselect utility to view the installed timezone. It comes handy when you want to know what time it is in other countries, or if you just wonder what timezones exist. tzselect is called without any parameters from the shell. It shows a list of about one dozen geographic areas one can roughly recognize as continents. After choosing a geographic area by number, a list of countries and cities in this area will be shown. You can press the [Enter] key to reprint the list. To choose a timezone, just press the number left to it. If your input is invalid, the list will be reprinted. You may press [CTRL] + [C] to interrupt the tzselect at any time.
$ tzselect
Sample outputs:

Fig.01: Setting the TZ variable with the tzselect utility

Fig.01: Setting the TZ variable with the tzselect utility

How Do I Change the Actual Timezone?

See all Redhat/CentOS/Fedora Core related FAQ
The tzselect command will not actually change the timezone for you. Use the redhat-config-date or setup command under RHEL / Fedora / Redhat / CentOS Linux to change the timzone:
# redhat-config-date
See all Debian/Ubuntu Linux related FAQ
Use the dpkg-reconfigure tzdata command under Debian or Ubuntu Linux to achieve the same thing:
$ sudo dpkg-reconfigure tzdata
See all FreeBSD related FAQ
Under OpenBSD or FreeBSD operating system you can set the timezone by creating softlink to /etc/localtime file.

A note about using the timedatectl command

Modern Linux distos with systemd as init will use the timedatectl command. First, show available time zones:
# timedatectl list-timezones
# timedatectl list-timezones | grep -i eastern

Outputs:

Canada/Eastern
US/Eastern

Next set the Time Zone to ‘US/Eastern’ or ‘America/New_York’ as follows:
# timedatectl set-timezone 'US/Eastern'
# OR #
# timedatectl set-timezone 'America/New_York'

Finally check that the time zone has been set correctly, run:
$ timedatectl
Showing my local time zone which I set to the IST:

               Local time: Wed 2024-03-20 03:43:34 IST
           Universal time: Tue 2024-03-19 22:13:34 UTC
                 RTC time: Tue 2024-03-19 22:13:33    
                Time zone: Asia/Kolkata (IST, +0530)  
System clock synchronized: yes                        
              NTP service: active                     
          RTC in local TZ: no      

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

4 comments… add one
  • Makella Jul 31, 2012 @ 18:37

    I am not sure if I my linux version supports the TZ variable . How do I find that out ? What versions of linux support this feature ?

  • ahmed Oct 15, 2012 @ 19:25

    thank you guys man you guys saved lots of my time!!!

    Thanks a lot.

  • grumpyoldphuker Oct 13, 2014 @ 15:13

    $ date

    why do youy lie to people wanting assistance in trying to understand something ??
    this shit does not work fuckhead……………………….

  • sivarni Sep 2, 2020 @ 17:39

    Useful information. Thanks a lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.