Facebook Dates and Pulling my (little) hair out!
Hi All
I am retrieving event information very cleverly using Facebook's graph API.
Alas it returns the date in the following format:
2010-12-12T05:30:00+0000
Now I have done the following to make it look more useful to the user, however I have noticed that the date is in fact wrong compared to how the event displays on facebook.
var eventDate = events.start_time;
var temp = eventDate.split("T");
eventDate = temp[0].split("-");
eventDate = eventDate[2] + "/" + eventDate[1] + "/" + eventDate[0];
var eventTime = temp[1].split("+");
var dateString = eventDate + " " + eventTime[0];
Is it possible to find out what timezone this was set to, and then deduct or add the local timezone difference to it? I am at a loss
Thanks All
3 Answers
-
Accepted Answer
I cannot tell you how much I hate javascript for this date logic….I have struggled a ton getting my project setup with this across multiple timezones. Anyways, it looks like the date format facebook is passing to you is a variant of ISO 8601.
You can look at this page for a way to parse the date and create a javascript date object, which you can then format appropriately. The bottom of the parse shows how to add in a timezone offset.
One thing that I didn't realize when first dealing with javascript dates is that they are almost all encoded as UTC with an offset. It takes a few hoops to simply ignore the timezone when processing.
-
I think JavaScript's one great feature will be your friend:
date = new Date('2010-12-12T05:30:00+0000');
Then you can format the date object as you like.
-
As far as I know the +0000 specifies the GMT+xx.xx ( hh:mm ) zone.