Why does `date` show UTC time, even with a different timezone set

datetimezone

I'm running Raspbian on a Pi 2. While I'm not sure this behavior was different previously, running date outputs the same time as date -u, despite my timezone being UTC-7. Below is the output of both of the above commands, and my $TZ variable:

pi@raspberrypi ~ $ date; date -u; echo $TZ
Sat Oct  3 05:33:43 America 2015
Sat Oct  3 05:33:43 UTC 2015
America/Los Angeles

How can I change this output to show the correct time/date? (eg. Oct 2 10:33:43 America 2015 as the output for date)

Best Answer

You have have the timezone set incorrect. To see if it works at all use some others (the extremes):

$ TZ=Pacific/Midway date
Mon Sep 28 20:42:02 SST 2015
$ TZ=Pacific/Kiritimati date
Tue Sep 29 21:42:48 LINT 2015

and if you double check your entry against the list you can see you're missing an underscore in the value of $TZ.

So try

$ TZ=America/Los_Angeles date

and see if your problem persists.

I haven't found any policy for the naming of the timezones, but spaces are never in them and replaced by underscore, but sometimes with a dash. It is probably best to look it up and copy/paste the value, something you, or your source didn't.

Related Question