2

I need to set my timezone to UTC -8, I only see options to set to PST or GMT-8. Is there a way to make it show as UTC-8?

I am running RHEL6.

$ date Sat Feb 23 01:41:41 UTC 2019

  • 1
    aren't UTC and GMT the same? – Jeff Schaller Feb 23 at 2:33
  • Technically, they're not the same, per that link. UTC is a standard, rather than a timezone, so shouldn't actually be an option for the timezone. I do recall a disagreement decades ago, in which UTC supported leap seconds and GMT didn't, which made them be different by a few seconds, but that's been resolved as TZ=GMT date; TZ=UTC date reports the same time twice, apart from calling one GMT and one UTC. – Ed Grimm Feb 23 at 2:39
2

You haven't said where you're setting this time zone, but you can invent any zone name you like in the TZ environment variable:

$ TZ='<UTC-8>+8' date
Fri Feb 22 19:25:36 UTC-8 2019

The +8 is because POSIX, stupidly, requires the offsets to be backwards (increasing westwards); the part in <...> is the displayed name and can be any single word. If it were purely alphabetic, the angle brackets wouldn't be required, but the - and 8 require them.

$ TZ='<yesterday>24' date
Fri Feb 22 03:30:15 yesterday 2019
$ TZ='tomorrow-24' date
Sun Feb 24 03:30:26 tomorrow 2019

If you're using a GUI or other zone-selection tool it is probably looking in /usr/share/zoneinfo for the zone definitions included in your system. If you want another zone to show up in that list, you would need to make a suitable zoneinfo file and copy it into place. The zic tool is used to compile zoneinfo files from the textual format, which is relatively straightforward (particularly when just modifying an existing zone to change the name).

On some systems (but not, I think, Red Hat), there is a file /etc/timezone that globally sets the time zone as a name, and you can use that TZ variable format in that. Other systems use only /etc/localtime, which is conventionally a copy of one of the zoneinfo files, so you'd need to make a suitable file there too.

For per-user or -session zones, you can only use the environment variable.


If you set the zone to "UTC-8" or some other zone that isn't specifically defined, it's treated as two things: first, a name for the zone ("UTC": whatever alphabetic string is there), and second an offset in POSIX orientation (whatever number is there). That means that TZ=UTC-8 date will output something like

Sat Feb 23 11:50:01 UTC 2019

- that is, it reports the time in China or Western Australia, and thinks the zone is called "UTC". This behaviour is deeply confusing and annoying to track down when you make a typo. It may be the cause of the output you included in the question, but I can't tell.

This is being parsed as the traditional, mostly-obsolete, POSIX time zone format RST6RDT5,M10.3.0/00:00:00,M2.4.0/00:00:00, which includes optional names and offsets for standard and daylight time, and dates of changeover between the two. There are a lot of drawbacks to this approach for any non-trivial zone, and it doesn't track historical changes of definition in the way that the zone files do.


The "correct" thing to do is to use either the America/Los_Angeles zone, which displays as PST, or Etc/GMT+8 if you can't use the name or don't want daylight savings changes. GMT+8 displays the offset as "-08" with no textual label. Sometimes the supposedly-correct thing isn't good enough, and in that case one of the above should be ok.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.