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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:56:05+00:00 2026-05-16T23:56:05+00:00

I render this JSON object: [{created_at:2010-09-21T20:41:28Z,subject:hello world}] Then I use this date parser to

  • 0

I render this JSON object:

[{"created_at":"2010-09-21T20:41:28Z","subject":"hello world"}]

Then I use this date parser to parse it (see below), but it only works in Chrome 6.0.4, Firefox 3.6.8, but NOT Safari 5.0.2 — I get NaN errors. What gives?

 Date.prototype.toRelativeTime = function(now_threshold) {
 var delta = new Date() - this;

 now_threshold = parseInt(now_threshold, 10);

 if (isNaN(now_threshold)) {
   now_threshold = 0;
 }

 if (delta <= now_threshold) {
  return 'Just now';
 }

 var units = null;
 var conversions = {
   millisecond: 1, // ms    -> ms
   second: 1000,   // ms    -> sec
   minute: 60,     // sec   -> min
   hour:   60,     // min   -> hour
   day:    24,     // hour  -> day
   month:  30,     // day   -> month (roughly)
   year:   12      // month -> year
 };

 for (var key in conversions) {
   if (delta < conversions[key]) {
     break;
    } else {
     units = key; // keeps track of the selected key over the iteration
     delta = delta / conversions[key];
   }
 }

 // pluralize a unit when the difference is greater than 1.
    delta = Math.floor(delta);
 if (delta !== 1) { units += "s"; }
 return [delta, units, "ago"].join(" ");
  };

/*
 * Wraps up a common pattern used with this plugin whereby you take a String
* representation of a Date, and want back a date object.
*/
  Date.fromString = function(str) {
      return new Date(Date.parse(str));
  };
  • 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-16T23:56:05+00:00Added an answer on May 16, 2026 at 11:56 pm

    The problem is that the Date constructor’s support for ISO 8601 is not present in all web browsers. You can do the following:

    Date.prototype.setISO8601 = function (string) {
        var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
            "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
            "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
        var d = string.match(new RegExp(regexp));
    
        var offset = 0;
        var date = new Date(d[1], 0, 1);
    
        if (d[3]) { date.setMonth(d[3] - 1); }
        if (d[5]) { date.setDate(d[5]); }
        if (d[7]) { date.setHours(d[7]); }
        if (d[8]) { date.setMinutes(d[8]); }
        if (d[10]) { date.setSeconds(d[10]); }
        if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
        if (d[14]) {
            offset = (Number(d[16]) * 60) + Number(d[17]);
            offset *= ((d[15] == '-') ? 1 : -1);
        }
    
        offset -= date.getTimezoneOffset();
        time = (Number(date) + (offset * 60 * 1000));
        this.setTime(Number(time));
    }
    

    then your code could look like this:

    var d = new Date("2010-09-13T11:51:50.9418504+02:00");
    if (isNaN(d)) {
        //alert("Date constructor not support ISO8601!");
        d = new Date();
        d.setISO8601("2010-09-13T11:51:50.9418504+02:00");
    }
    

    The code is not from me. I found it on the internet, but I could not find the original source.

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

Sidebar

Related Questions

Hello i'm trying to convert my Java Object to a Json string to use
Update: This issue was not properly explored. The real issue lies within render :json
right now I'm creating an array and using: render :json => @comments This would
I am trying to render an object as json, including nested attributes and sort
I have an HBITMAP containing alpha channel data. I can successfully render this using
Many times I see statements like following Y.CustomApp.superclass.render.apply(this, arguments); I know how apply works.
I have this piece of code for render a popup, using f:ajax: <h:commandButton id
Why does this graphml file below does not render the node color properly in
Why doesn't this Google Chart API URL render both data sets on this XY
How would I do this (C#) in F# public class MyClass { void Render(TextWriter

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.