0

I am using Codeigniter's date helper to obtain the user's timezone offset, [by storing it in a database in mysql]. link

Anyways, all I really have is the offset, since the stored information [in the DB] is customized to CodeIgniter. fore example UM7 is equal to an offset of -7 from GMT.

I get my offset by using timezones($this->session->userdata('timezone')), which spits out -7 [or whatever, depending on what the DB stores.].

Anyways, how can I set PHP's own date_default_timezone_set() to the user's local time? I can't input numbers in there because i believe that function only allows for strings, like "America/Phoenix" or something like that. All I have is the offset.

And to make it even more complicated, will PHP automatically detect DST and change accordingly? [because some states in the USA, such as Arizona, does not participate in DST] Thanks!

Jeromie Devera
  • 376
  • 2
  • 6
  • 21
  • 1
    TZ offsets can NOT help you with local variances, like Arizona. that's why there's the `America/Phoenix` zones, which DO let you look up those local variances. if all you have is GMT-7, it's impossible to determine if that's really MST or PDT - both are -7 – Marc B Mar 13 '14 at 01:56
  • Yes you can input numbers http://www.php.net/manual/en/timezones.others.php `Etc/GMT-7`. But Marc's method is very much preferred. – Mike B Mar 13 '14 at 02:05
  • Oh, I see. So I should probably redo the the signup form so that instead of storing an offset in the DB, it would store individual zones. Or maybe somehow detect DST by matching the computer's time vs the time in the server? [I believe vBulletin does something like this] and if they don't match, change DST settings accordingly? – Jeromie Devera Mar 13 '14 at 02:10
  • possible duplicate of [how to detect users timezone](http://stackoverflow.com/questions/16525617/how-to-detect-users-timezone) – Matt Johnson-Pint Mar 15 '14 at 21:04

0 Answers0