Sample Header Ad - 728x90

"export TZ=`date +%Z`" leads to confusing output of "date"

2 votes
1 answer
2338 views
I recently noticed the following (strange) behavior: user@pc:~$ date Mi 21. Jun 12:03:10 CEST 2017 user@pc:~$ date +%Z CEST user@pc:~$ export TZ=date +%Z user@pc:~$ date Mi 21. Jun 10:03:30 CEST 2017 user@pc:~$ date +%Z CEST Thus, after setting the TZ environment variable to the current system time zone, the clock is 2 hours delayed. It looks like UTC (CEST-2hours is UTC). If I now set TZ to other values, the clock remains unchanged: user@pc:~$ export TZ=UTC user@pc:~$ date Mi 21. Jun 10:07:09 UTC 2017 user@pc:~$ export TZ=PDT user@pc:~$ date Mi 21. Jun 10:07:19 PDT 2017 However, when I set TZ to CEST-2, it works fine again. I am a bit confused user@pc:~$ export TZ=CEST-2 user@pc:~$ date Mi 21. Jun 12:28:16 CEST 2017 I am working on xUbuntu 16.04 but this behavior is reproducible on a OpenSUSE 42.2 System. It seems to me that a time zone "ABC+X" is always considered as "UTC+X" when there is no /usr/share/zoneinfo/ABC file (thanks DevilaN for the comment). The string "ABC" is than only inserted into the date string, which is printed out. Questions: 1. Is the assumption described above correct? 2. Why does date print out a time zone abbreviation that is not supported (i.e. not available in /usr/share/zoneinfo)?
Asked by daniel.heydebreck (162 rep)
Jun 21, 2017, 10:34 AM
Last activity: Oct 14, 2024, 05:14 AM