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 469515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:47:25+00:00 2026-05-12T23:47:25+00:00

My JSON string contains a date field that returns such a value: 2009-04-04T22:55:16.0000000-04:00 I

  • 0

My JSON string contains a date field that returns such a value:

"2009-04-04T22:55:16.0000000-04:00"

I am particularly interested in parsing only the date compartment not the time. I tried using a reviver function, but interestingly the reviver function is never invoked! (tried on Firefox)

Here is my code to accomplish that:

var Site = {
.....
dateReviver: function(key, value) {
    var a;
    if (typeof value === 'string') {
        a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
        if (a) {
            return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
        }
    }
    return value;
},
loadArticle: function(id) {
....
    proxy.getArticle(id, function(response) {
        var data = JSON.parse(response.result, Site.dateReviver);
        ....
    });
}
};

JSON.parse in loadArticle never calls dateReviver.

I invested a whole day but no luck! Could someone please help me?

  • 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-12T23:47:26+00:00Added an answer on May 12, 2026 at 11:47 pm
    1. The regular expression expects a “Zulu” timezone (A ‘Z’ character at the end), while the sample date-time string shows a numeric timezone (‘-04:00’). The following regex will accept both:

      /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)(Z|([+\-])(\d{2}):(\d{2}))$/
      

      If the time zone digits are not zero, you might want to actually modify the date after parsing and/or converting to UTC, to respect the timezone.

    2. I can see dateReviver() being hit. Try the following in a browser:

      <!-- saved from url=(0014)about:internet -->
      <html>
          <head>
              <script src="http://www.json.org/json2.js"></script>
              <script type="text/javascript" src="http://ajax.Microsoft.com/ajax/jQuery/jquery-1.3.2.js"></script>
              <script>
                  $(function () {
                      // a mock proxy to return some json to play with
                      var proxy = {
                          getArticle: function(id, foo) { foo({
                              result: '["2009-04-04T22:55:16.0000000-04:00"]'
                          }); }
                      };
                      // the origial Site object, with the fixed regex
                      var Site = {
                          dateReviver: function(key, value) {
                              var a;
                              if (typeof value === 'string') {
                                  a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)(Z|([+\-])(\d{2}):(\d{2}))$/.exec(value);
                                  if (a) {
                                      return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                                                      +a[5], +a[6]));
                                  }
                              }
                              return value;
                          },
                          loadArticle: function(id) {
                              proxy.getArticle(id, function(response) {
                                  var data = JSON.parse(response.result, Site.dateReviver);
                                  // put the parsed JSON date on the page
                                  $("#output").html(data[0].toString());
                              });
                          }
                      };
                      // try out our Site object
                      Site.loadArticle();
                  });
              </script>
          </head>
          <body>
              <div id="output"></div>
          </body>
      </html>
      

      I am getting the following in the browser, indicating successful parsing:

      Sat Apr 4 15:55:16 PDT 2009
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got below JSON string, i facing issue parsing because it contains non english
I'm using JQuery to call a PHP function that returns a JSON string upon
I have a JSON object being returned to my app that contains a date
I have a json string that contains the values for a datetime and a
I've got a AJAX call that returns a JSON string containing several different DateTimes.
I store a json string that contains some (chinese ?) characters in a mysql
This results in a JSON string that contains street_number - http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false long_name : 1600,
I have a simple json string which contains a collection of objects http://sandapps.com/InAppAds/ads.json.txt When
For a JSON string, contains all kinds of settings, numbers, text etc (no fancy
Take the following JSON string (generated by some ExtJS code - but that's irrelevant):

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.