Get time for system default timezone

datetimezone

When logging in to remote machine X, by default, date will give the time in the local timezone:

$ date
Mon Nov 17 22:45:47 CET 2014

Note that TZ is not set:

$ export | grep TZ
$ 

So, I set TZ to my own local timezone for every machine I'm on:

$ export TZ=/usr/share/zoneinfo/Canada/Eastern
$ date
Mon Nov 17 16:46:13 EST 2014

The question is, once I have this set, how do I get the time for the system default timezone, i.e. the timezone that applies if I, as a user, do not manually set TZ? Unsetting TZ gives me the UTC time, which is not what I seek:

$ TZ= date
Mon Nov 17 21:47:13 UTC 2014

Interestingly, TZ= date gives UTC time, even when I didn't yet set TZ to anything; yet when I didn`t yet set TZ to anything, a simple date gave the date in the system default timezone…

Best Answer

Try unsetting the TZ variable (which is different from setting it to ""):

$ (date; export TZ=/usr/share/zoneinfo/Canada/Eastern; date; unset TZ; date)
Tue Nov 18 03:25:25 IST 2014
Mon Nov 17 16:55:25 EST 2014
Tue Nov 18 03:25:25 IST 2014

Note how I tried it in a subshell, so that my current shell remains unaffected.

Related Question