SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date.parse problem!

    I have a program that parses the same date differently using the same function.

    The date is a string from facebook:

    "2010-07-19T18:00:52+0000"

    In one part of my js program, I execute:
    created_at = Date.parse("2010-07-19T18:00:52+0000")

    On another page, I execute the same:
    created_at = Date.parse("2010-07-19T18:00:52+0000")

    Displaying created_at in my html will yield either

    Mon, 19 Jul 2010 19:48:59 GMT or
    Mon Jul 19 2010 19:48:59 GMT-0700 (PST)

    Ideally I'd like the date to be read as a GMT. Are there global settings to Date that I should be setting to get consistent interpretation of the fb string?

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm surprised that works. This line:

    Code:
    created_at =  Date.parse("2010-07-19T18:00:52+0000")
    doesn't work. Date.parse can't handle strings like that. In any case, once you have somehow parsed your date, you can use toUTCString() to convert things to GMT. But you will need to turn that string returned into a Date object first. Example:

    Code javascript:
    var sometime = new Date(Date.parse('Wed 07 Jul 2010 13:24:30 GMT-0530'));
    alert(sometime.toUTCString());

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ..er

    It turns out to be my error. Date.parse() is actually not parsing the same value on the different pages. One page is parsing the facebook value, the other (working one) is parsing an already parsed date.

    Incidently, it turns out that Date.parse is coming from the jquery.daterangepicker module...

    Thanks for the reply,


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •