2

How do you convert a timezone from int to string (etc: Europe/Stockholm)?

I'm using Facebooks PHP api and that returns ["timezone"] => int(2). How am I suppose to parse that?

Marwelln
  • 28,492
  • 21
  • 93
  • 117

2 Answers2

6

How do you convert a timezone from int to string (etc: Europe/Stockholm)?

You can't. Read "Time Zone != Offset" in the timezone tag wiki.

Facebook's documentation explains that the timezone field is the user's timezone offset from UTC.

What it doesn't make clear, but I have found through experimentation, is that it is not necessarily the user's current offset, but it instead it is the offset as of the user's last log in. If the user changes time zones, or daylight saving time begins or ends, that will not be reflected in the Facebook data until the user's next log in.

See also these posts:

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
2

You can get the timezone name by using timezone_name_from_abbr("", $value*3600, false);. $value is the timezone offset you get from Facebook.

Thanks to minaz.

Community
  • 1
  • 1
Marwelln
  • 28,492
  • 21
  • 93
  • 117
  • 1
    This will create a fixed time zone for that offset, which is probably the best you can do under these circumstances. But understand that it is not the same as `Europe/Stockholm`, which alternates between UTC+1 and UTC+2. – Matt Johnson-Pint Oct 21 '13 at 17:21