0

Is there a timezone 'code' that includes the offset (for example: -7) that the function date_default_timezone_set() would accept? (I only have the offset number, and not something specific like America/Phoenix).

I'm setting timezones based off of Facebook's API, when I extract the user's information.

Anand Solanki
  • 3,419
  • 4
  • 16
  • 27
Jeromie Devera
  • 376
  • 2
  • 6
  • 21
  • possible duplicate of [Parse timezone int to string (timezone name) (facebook api)](http://stackoverflow.com/questions/19489257/parse-timezone-int-to-string-timezone-name-facebook-api) – Matt Johnson-Pint May 22 '14 at 13:48

2 Answers2

1

No. Time zones don't work that way. A time zone offset only applies to a specific point in time. Many time zones share the same offset at various times. Some are indistinguishable from others with an offset alone.

For example, -7 could be MST, or it could be PDT. It might be used with "America/Phoenix", which is on MST year-round. But it might belong to "America/Denver" which would use MST (-7) in the winter and MDT (-6) in the summer. Or it might belong to "America/Los_Angeles", using PST (-8) on the winter and PDT (-7) in the summer.

See also, the timezone tag wiki

Regarding Facebook, it's only giving you the time zone offset as of the user's last login. It is not necessarily even the correct offset for the current moment in time.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Can't I just recheck every time the user goes on my website? Or does the user have to log out of facebook and relogin in order for the timezone to change? – Jeromie Devera May 27 '14 at 02:40
  • Facebook just calls JavaScript `new Date().getTimezoneOffset()` when the user logs in and saves it in the user's profile. If the offset changes before the user's next login (for example, crossing a DST transition), their profile will not reflect that. – Matt Johnson-Pint May 27 '14 at 15:32
0

you can use a specific array. For example, $timezone = array("-7"=>"America/Phoenix", "-6" =>"oneplace/somewhere" ......... );

Therefore, you can use date_default_timezone_set($timezone[-7]);

Pascal

SkaJess
  • 886
  • 7
  • 9