17

I am trying to use 'date' to get the time in a different time zone, and failing. All the methods I've found on google involve changing the time zone on the system, but that is not what I want.

Is there a single command that will return current time in a time zone different from my own?

ID-ZERO
  • 331
  • See also my answer here for a way that doesn't require knowing the exact name of the wanted timezone: https://stackoverflow.com/a/59751090/111036 – mivk Mar 25 '22 at 13:06

3 Answers3

28

Timezones are listed in /usr/share/zoneinfo. If you wanted the current time in Singapore, for example, you could pass that to date:

TZ=Asia/Singapore date
Sun Jun 14 17:17:49 SGT 2015

To simplify this procedure, if you need to frequently establish the local time in different timezones, you could add a couple of functions to your shell rc file (eg, .bashrc):

zones() { ls /usr/share/zoneinfo/"$1" ;}
zone() { TZ="$1"/"$2" date; }

The first will print the correct zone list for a region, and armed with that information, you can then print the local time.

jasonwryan
  • 73,126
13

You can use zdump:

NAME
       zdump - timezone dumper

SYNOPSIS
       zdump [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] [ zonename ... ]

DESCRIPTION
       Zdump prints the current time in each zonename named on the command line.

Example:

$ zdump ~$ zdump Iceland
Iceland  Sun Jun 14 09:40:30 2015 GMT

$ zdump Japan
Japan  Sun Jun 14 18:34:36 2015 JST

The time zone data file is locate at /usr/share/zoneinfo.

You can also print time of all by find /usr/share/zoneinfo/ -type f | xargs zdump. And can grep for particular example for dubai

$ find /usr/share/zoneinfo/ -type f | xargs zdump | grep -i Dubai
/usr/share/zoneinfo/right/Asia/Dubai                      Sun Jun 14 13:38:26 2015 GST
/usr/share/zoneinfo/Asia/Dubai                            Sun Jun 14 13:38:51 2015 GST

You can use gworldclock:-

NAME
       gworldclock - Displays time and date in specified time zones.

SYNOPSIS
       gworldclock [ -f FILE ]

DESCRIPTION
       gworldclock  displays  the  time  and  date of specified time zones using a GTK+ interface. It also allows the
       zones to be "rendezvoused" or "synchronised" to a time other than the current time.

screenshot

Pandya
  • 24,618
9

Almost all programs use the TZ environment variable to determine the timezone, and fall back to the system setting if that variable is not set.

TZ=Pacific/Yap date
TZ=Pacific/Yap xclock

Almost all operating systems (even Windows) use timezone information from the IANA database. Most timezones have a name of the form Continent/Town where Town is typically the largest city of a country or region which defines its own timezone rules. A few abbreviations are defined, like CET for Central European time and EST for Eastern Standard Time, but they might not always be what you expect because of conflicts across locales (e.g. EST is the US one, not the Australian one). Time zone rules are usually defined by files in /usr/share/zoneinfo, /usr/lib/zoneinfo, /usr/lib/locale/TZ or some similar location.

There are standard values for the TZ variable as well. If you want a fixed offset from UTC, you can use something like TZ=-4 (4 hours east of GMT) or TZ=9:30 (9½ hours west of GMT).