Objective: Get the current time in a different timezone on Linux without changing the system timezone.
The easiest way to show the current time on a different timezone is to set the TZ
environment variable before calling date
. To show the current time in Singapore, set TZ
to Asia/Singapore
.
1 2 |
$ TZ=Asia/Singapore date Sun May 21 18:01:48 SGT 2017 |
To get the list of possible values of TZ
, use tzselect
or timedatectl
commands. tzselect
is a menu driven utility to view timezones and to view timezones using timedatectl
, use the list-timezones
option. To list all timezones in Asia using timedatectl
, use the following command syntax.
1 |
$ timedatectl list-timezones | grep Asia |
The other method is to use zdump
utility to print the time in a different timezone. To get the current time in Singapore using zdump
, use the following command syntax.
1 2 |
$ zdump Asia/Singapore Asia/Singapore Sun May 21 18:22:41 2017 SGT |