Last Updated: February 25, 2016
·
3.918K
· siefca

GNU/Linux: time zone for a specific user

Sometimes we have account on GNU/Linux operating system that is located in a different time zone and its system-wide TZ setting doesn't reflect our reality.

It is possible to have different time zone setting for a process and all processes that are its descendants. That process can be a login shell.

To setup different time zone just edit ~/.bashrc file and add the following:

TZ="/usr/share/zoneinfo/CONTINENT/CITY"
export TZ

replacing CONTINENT and CITY with preferred values, for instance:

TZ="/usr/share/zoneinfo/Europe/Warsaw"
export TZ

To commit the changes immediately do:
source ~/.bashrc or . ~/.bashrc

Such setting will have effect on any Bash process executed by you, even non-interactive. If you would like only interactive shell to use different time zone settings, you have to edit different file, e.g. ~/.bash_profile for Bash or ~/.profile for POSIX-compliant shells.

To manually ensure that the changes are made for just login shell processes you may add simple condition around:

if [ "$PS1" ]; then
  TZ="/usr/share/zoneinfo/Europe/Warsaw"
  export TZ
fi

Before you apply these instructions check if the directory /usr/share/zoneinfo contains proper files and directories. If not, ask your system administrator to install tzdata package.