Posted by: Dakusan
« on: March 23, 2011, 10:54:31 pm »Original post for Setting the time zone through a numeric offset can be found at https://www.castledragmire.com/Posts/Setting_the_time_zone_through_a_numeric_offset.
Originally posted on: 03/23/11
Originally posted on: 03/23/11
I had the need today to be able to set the current time zone for an application in multiple computer languages by the hourly offset from GMT/UTC, which turned out to be a lot harder than I expected. It seems most time zone related functions, at least in Linux, expect you to use full location strings to set the current time zone offset (i.e. America/Chicago).
After a lot of research and experimenting, I came up with the following results. All of these are confirmed working in Linux, and most or all of them should work in Windows too.
Language | Format Note | Format for GMT+5 | Format for GMT-5 |
---|---|---|---|
C | Negate | GMT-5 | GMT5 |
Perl | Negate | GMT-5 | GMT5 |
SQL | Requires Sign | +5:00 | -5:00 |
PHP | Negate, Requires Sign | Etc/GMT-5 | Etc/GMT+5 |
And here are examples of using this in each language. The “TimeZone” string variable should be a 1-2 digit integer with an optional preceding negative sign:
Language | Example |
---|---|
C |
|
Perl |
|
SQL [Query string created via Perl] |
|
PHP |
|