Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:08:29+00:00 2026-05-26T23:08:29+00:00

So I am writing an application using ajax getting from a xml based api.

  • 0

So I am writing an application using ajax getting from a xml based api. The api returns dates in the following format:

2011-11-12T13:00:00-07:00

I need to get this as a standard JavaScript date object

var myDate = new Date('2011-11-12T13:00:00-07:00');

which works great in every browser BUT ie8 and ie7. I just don’t understand why and can’t seem to find any documentation on how to format this specifically for ie7-8. I know there has to be a smart way to do this. Please help. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:08:30+00:00Added an answer on May 26, 2026 at 11:08 pm

    The only smart way is to parse the string and manually create a date object. It’s not hard:

    var dateString = '2011-11-12T13:00:00-07:00';
    
    function dateFromString(s) {
      var bits = s.split(/[-T:]/g);
      var d = new Date(bits[0], bits[1]-1, bits[2]);
      d.setHours(bits[3], bits[4], bits[5]);
    
      return d;
    }
    

    You probably want to set the time for the location, so you need to apply the timezone offset to the created time object, it’s not hard except that javascript date objects add the offset in minutes to the time to get UTC, whereas most timestamps subtract the offset (i.e. -7:00 means UTC – 7hrs to get local time, but the javascript date timezone offset will be +420).

    Allow for offset:

    function dateFromString(s) {
      var bits = s.split(/[-T:+]/g);
      var d = new Date(bits[0], bits[1]-1, bits[2]);
      d.setHours(bits[3], bits[4], bits[5]);
    
      // Get supplied time zone offset in minutes
      var offsetMinutes = bits[6] * 60 + Number(bits[7]);
      var sign = /\d\d-\d\d:\d\d$/.test(s)? '-' : '+';
    
      // Apply the sign
      offsetMinutes = 0 + (sign == '-'? -1 * offsetMinutes : offsetMinutes);
    
      // Apply offset and local timezone
      d.setMinutes(d.getMinutes() - offsetMinutes - d.getTimezoneOffset())
    
      // d is now a local time equivalent to the supplied time
      return d;
    } 
    

    Of course is it much simpler if you use UTC dates and times, then you just create a local date object, setUTCHours, then date and you’re good to go – the date object will do the timezone thing (provided the local system has it set correctly of course…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application that converts an ajax xml response into html using
I am writing a web application which retrieves a lot of data using AJAX
I'm writing a very AJAX-intensive application using Rails 3.0.4, and testing it with RSpec.
I'm writing single-page web application. Client interacts with server using AJAX retrieving quite complex
I am writing an application using labview and need to use external code. I
I am writing an application using Core Data to control a few NSTableViews. I
I am writing an application using the MVVM pattern. I am providing data to
I'm writing an application using DDD techniques. This is my first attempt at a
I have problem concerning python packages and testing. I'm writing an application using wx
I'm writing a web application using Spring/Hibernate that displays a report to a user,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.