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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:25:34+00:00 2026-05-30T09:25:34+00:00

Is there a string format of a date that a Date object can be

  • 0

Is there a string format of a date that a Date object can be built from (i.e. new Date('date string')) that works in all browsers and localities/timezones?

We’ve tried using the format suggested in the HTML5 spec of yyyy-mm-ddThh:mm:ss+hh:mm, but ran into issues with Safari and IE. We’ve tried using the less-formal format of mm/dd/yyyy hh:ss:mm which works but, as far as I know, “month before day” formatting can be ambiguous if your locale settings assume the first number to be a day (non-American countries). Also, it doesn’t attach a timezone which would have issues with different timezones.

  • 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-30T09:25:35+00:00Added an answer on May 30, 2026 at 9:25 am

    In short that’s an almost impossible promise to make as the implementation is UA dependent. I would recommend using the iso8601 format as it will be standard going forward and use a shim to aid in the date parsing here is one I wrote for my own use:

    (function() {
    
    var d = window.Date,
        regexIso8601 = /^(\d{4}|\+\d{6})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})\.(\d{1,3})(?:Z|([\-+])(\d{2}):(\d{2}))?)?)?)?$/;
    
    if (d.parse('2011-11-29T15:52:30.5') !== 1322581950500 ||
        d.parse('2011-11-29T15:52:30.52') !== 1322581950520 ||
        d.parse('2011-11-29T15:52:18.867') !== 1322581938867 ||
        d.parse('2011-11-29T15:52:18.867Z') !== 1322581938867 ||
        d.parse('2011-11-29T15:52:18.867-03:30') !== 1322594538867 ||
        d.parse('2011-11-29') !== 1322524800000 ||
        d.parse('2011-11') !== 1320105600000 ||
        d.parse('2011') !== 1293840000000) {
    
        d.__parse = d.parse;
    
        d.parse = function(v) {
    
            var m = regexIso8601.exec(v);
    
            if (m) {
                return Date.UTC(
                    m[1],
                    (m[2] || 1) - 1,
                    m[3] || 1,
                    m[4] - (m[8] ? m[8] + m[9] : 0) || 0,
                    m[5] - (m[8] ? m[8] + m[10] : 0) || 0,
                    m[6] || 0,
                    ((m[7] || 0) + '00').substr(0, 3)
                );
            }
    
            return d.__parse.apply(this, arguments);
    
        };
    }
    
    d.__fromString = d.fromString;
    
    d.fromString = function(v) {
    
        if (!d.__fromString || regexIso8601.test(v)) {
            return new d(d.parse(v));
        }
    
        return d.__fromString.apply(this, arguments);
    };
    
    })();
    

    Now instead use Date.fromString(....) and everyone will be happy in the land of OZ!

    works in all major browsers, used these references:

    http://dev.w3.org/html5/spec/common-microsyntaxes.html

    http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15

    http://msdn.microsoft.com/en-us/library/windows/apps/ff743760(v=vs.94).aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/wz6stk2z(v=vs.94).aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/k4w173wk(v=vs.94).aspx

    https://connect.microsoft.com/IE/feedback/details/723740/date-parse-and-new-date-fail-on-valid-formats

    hope this helps -ck

    UPDATE: (1/21/2013)

    It should be noted that the behavior of what’s considered “standards-compliant behavior” is going to change from ECMAScript-262 v5.1 to ECMAScript-262 v6.0. See: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.9.1.15

    The language went from: The value of an absent time zone offset is “Z”. to If the time zone offset is absent, the date-time is interpreted as a local time.

    The pickle right now is: chrome, opera and mobile safari follow ES5.1, whereas IE10, firefox and desktop safari seem to be following ES6. So it’s kind of a split decision right now… So as such there needs to be a second ES6 standard-compliant version of this script, and here ya go:

    (function() {
    
        var d = window.Date,
            regexIso8601 = /^(\d{4}|\+\d{6})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})\.(\d{1,})(Z|([\-+])(\d{2}):(\d{2}))?)?)?)?$/,
            lOff, lHrs, lMin;
    
        if (d.parse('2011-11-29T15:52:30.5') !== 1322599950500 ||
            d.parse('2011-11-29T15:52:30.52') !== 1322599950520 ||
            d.parse('2011-11-29T15:52:18.867') !== 1322599938867 ||
            d.parse('2011-11-29T15:52:18.867Z') !== 1322581938867 ||
            d.parse('2011-11-29T15:52:18.867-03:30') !== 1322594538867 ||
            d.parse('2011-11-29') !== 1322524800000 ||
            d.parse('2011-11') !== 1320105600000 ||
            d.parse('2011') !== 1293840000000) {
    
            d.__parse = d.parse;
    
            lOff = -(new Date().getTimezoneOffset());
            lHrs = Math.floor(lOff / 60);
            lMin = lOff % 60;
    
            d.parse = function(v) {
    
                var m = regexIso8601.exec(v);
    
                if (m) {
                    return Date.UTC(
                        m[1],
                        (m[2] || 1) - 1,
                        m[3] || 1,
                        m[4] - (m[8] ? m[9] ? m[9] + m[10] : 0 : lHrs) || 0,
                        m[5] - (m[8] ? m[9] ? m[9] + m[11] : 0 : lMin) || 0,
                        m[6] || 0,
                        ((m[7] || 0) + '00').substr(0, 3)
                    );
                }
    
                return d.__parse.apply(this, arguments);
    
            };
        }
    
        d.__fromString = d.fromString;
    
        d.fromString = function(v) {
    
            if (!d.__fromString || regexIso8601.test(v)) {
                return new d(d.parse(v));
            }
    
            return d.__fromString.apply(this, arguments);
        };
    
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to create a new NSString from a format string like
Is there a format string (?) I can pass to the VB6 Format function
Are there any codes that allow for numerical formatting of data when using string.format?
Is there any way I can specify a standard or custom numeric format string
Is there an easy way to convert a string from csv format into a
Is there a way to format a UTC time into any arbitrary string format
Is there any performance differences between string.Format and String.Format ? As far as i
In the application there is a string in the following format: String elements =
I am wondering if there is a method or format string I'm missing in
Is there any way to format a string by name rather than position in

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.