The TZ (time zone) environment variable is used to specify the time zone that a system or application should use for time and date calculations. The value of the TZ variable is usually a string that specifies the time zone name, such as America/Los_Angeles
for Pacific Time, or Asia/Shanghai
for China Standard Time.
The TZ variable can be set in several ways, including:
- In the
/etc/localtime
file: This file is a symbolic link to a file in the/usr/share/zoneinfo
directory that defines the time zone for the system. By changing the symbolic link, you can change the time zone for the entire system. - In the system environment: You can set the TZ variable in the system environment so that it will be available to all users and applications on the system. This can be done by adding the following line to the
/etc/environment
file:
TZ=America/Los_Angeles
- In the user environment: You can set the TZ variable in your user environment so that it will only be available to you. This can be done by adding the following line to your
~/.bashrc
file:
export TZ=America/Los_Angeles
- As a command line option: You can set the TZ variable for a single command by passing it as an option when you run the command. For example:
bash
TZ=America/Los_Angeles date
It’s important to note that different applications may use different methods for reading the TZ variable, and some may not use it at all. Consult the documentation for each application to see how it handles time zones.