I want to set the system date and timezone based on a string that looks like this (output of Javascript new Date().toString()):

Fri Aug 01 2014 12:13:27 GMT+0200 (CEST)

The standard way to set timezone on a Debian system is to run tzselect or to symlink a zone file from /usr/share/zoneinfo onto /etc/localtime. In both cases, I need to know the timezone by continent/city.

Is there an easy way to set the timezone based on GMT offset only?

  • There seem to be GMT+X timezones in /usr/share/zoneinfo/Etc/, but only for the full hours, so this won't work with half or quarter hour offsets. Aug 1, 2014 at 10:29
  • I found a workaround for my particular application, which is to synchronize a server's date and time to a client PC by auto-submitting the client time from a webpage: Use jstz to get a standard timezone info, submit that along with the timestamp, and use it to identify the correct file in /usr/share/zoneinfo. Aug 1, 2014 at 10:47

1 Answer 1


There is in general not enough information in that date string to know which timezone it was generated in. The +0200 only tells you that the timezone in question is currently ahead of UTC by two hours. It doesn't tell you whether the offset changes throughout the year or from year to year like knowing the actual time zone would tell you. As for the CEST part, those short timezone names are not meant to be unique (several different timezones may all call themselves CEST).

As you pointed out in a comment, you can use the string to guess one of the Etc/* timezones which are at fixed offsets from UTC at all times, but that's it. And also, not all possible offsets exist as Etc/* timezones, for example Nepal's +0545.

Since you also pointed out in a comment that you need this just for a particular application, so perhaps you might be interested in changing the timezone just for the current process (your application's process) using the TZ environment variable? Using that you could set a timezone line this:


You have everything you need in the date string you have quoted to do that. (Note the opposite sign on the offset.)

  • 1
    I didn't realize how ambiguous these time zone abbreviations are! In Wikipedia's "List of time zone abbreviations", there are 14 of them which have multiple meanings, and "CST" can refer to four different time zones. Aug 1, 2014 at 13:27
  • 1
    The TZ variable is actually a valid solution for my problem, since it allows you to specify a HH:MM offset such as TZ=UTC+05:45. The fact that the offset may change over time is acceptable since the timezone is updated every time the application is used. Aug 1, 2014 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .