Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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:


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

— asked December 1st 2010 by Justin Howard
  • date
  • javascript
  • timezone

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.

    — answered December 3rd 2010 by Mike Robinson
  • 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.

    — answered January 4th 2012 by Kristof Gruber
    1 Comment
    • Running across the issue in this thread also. Kristof, did you actually try that? Because it doesnt work.

      — commented December 10th 2012 by j ro
  • As far as I know the +0000 specifies the GMT+xx.xx ( hh:mm ) zone.

    — answered December 1st 2010 by Dan Tamas
    1 Comment
    • Thats pretty much what I managed to suss out, But I dont know how to make the date change subject to the Timezone. Say I want -8hours from the date above?

      — commented December 1st 2010 by Justin Howard
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.