IE Date.Parse() returns NaN

Related searches

I am trying to parse this string

"2017-06-01 11:22:20.683"

It is working just fine in Firefox, but return NaN in IE 11 Unfortunately I am unable to modify the source string since its coming from a legacy system.

function myFunction() {
    var d = Date.parse("2017-06-01 11:22:20.683");
    document.getElementById("demo").innerHTML = d;
}
<p id="demo"></p>
<button onclick="myFunction()">Try it</button>

Here is the simpliest solution:

function myFunction(dateString) {
    var str = dateString.replace(/^(.*-[0-9][0-9])(\ )([0-9][0-9]\:.*$)/, '$1T$3')
    var d = Date.parse(str);
    document.getElementById("demo").innerHTML = d;
}

IE Date.parse method returns NaN for Date with Time string, If you can put your input in this form: YYYY/MM/DDThh:mm:ss. It will work. Eg: alert(new Date(Date.parse('2010-01-31T12:00:00.233467-05:00'.replace(/\-/ig,� Using Date.parse(“2017-02-13 04:33:00.0”) I’m shown that it’s NaN. Using Date.parse(“2017-02-13 04:33:00”) without the millisecond results in a correctly parsed date. Therefore, get

Unfortunately this API is not quite reliable. Edge still gives you a NaN. You have two options though:

1) Use an external library called MomentJS. Very easy to use and have all corner cases implemented. (http://momentjs.com/docs/)

2) Refer to this question to parse it manually: Why does Date.parse give incorrect results?

Hope that helps

Shows date as NAN in IE only - JavaScript, getMonth() + 1) + "/" + dateObject.getDate() + "/" + dateObject. Using Date. parse(“2017-02-13 04:33:00.0”) I'm shown that it's NaN. Date constructor returns NaN in IE, but works in Firefox and Chrome. javascript� Javascript JSON Date parse in IE7/IE8 returns NaN. javascript date internet-explorer-8 utc internet-explorer-7. demandé sur Bergi 2012-06-13 22:00:15.

Please do not replace the '-' with '/', use whitespace instead.

var str = "15-Dec-2019 05:25:45 PM ";
console.log( Date.parse( str.replace(/-/g, ' ') ) );

This worked for me in Chrome and Firefox browsers, i hope, this will help you also.

Date.parse(), It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. UTC() method accepts parameters similar to the Date constructor, but treats UTC(1); // Safari: NaN // Chrome/Opera/V8: NaN // Firefox <54: non-NaN // Firefox 54+: NaN // IE: non-NaN // Edge: NaN. See also. Date.parse() � Date� JavaScript new Date() Returning NaN in IE or Invalid Date in Safari February 8th, 2011 - Posted by Steve Marks to Javascript / jQuery , Web Development . When it comes to programming, working with dates can be tricky.

/// Below example will work in All Browser including IE
<script>
 var selected_date = '2019,Apr,05'; // You need to change date format like this
 var parsing_date = Date.parse(selected_date.replace(/^(.*-[0-9][0-9])(\ )([0-9][0-9]\:.*$)/, '$1T$3'));
 alert(parsing_date); 
</script> 

Date.UTC(), Return Values: It returns an integer value representing the number of a millisecond between midnight January 1, 1970, and the date provided. If by any means, the machine can’t recognize the string or the input string is invalid, it will return “NaN” instead of an integer.

Phương thức Date.parse() phân tích cú pháp của một chuỗi đại diện của một ngày và trả về số mili giây kể từ 01 tháng 01 năm 1970, 00:00:00 UTC hoặc NaN nếu chuỗi không nhận dạng được hoặc trong một số trường hợp, chứa các giá trị ngày không hợp lệ (ví dụ 2015-02-31).

Return value. An integer parsed from the given string. Or NaN when. the radix is smaller than 2 or bigger than 36, or; the first non-whitespace character cannot be converted to a number. Description. The parseInt function converts its first argument to a string, parses that string, then returns an integer or NaN.

After installing datejs Date.parse() returns null instead of NaN This breaks compatibility with the stock Date() object which in turn breaks the conditional request logic in express.static causing spurious HTTP 412 responses.

Comments
  • Maybe its because its not ISO8601 compliant. Try "2017-06-01T11:22:20.683" instead.
  • unfortunately I cannot modify the source.
  • Of course you can modify the string, you have it in javascript and can do anything you want to it. To say otherwise is just nonsense.
  • cannot modify the source date format, but I can code js/jquery around it to parse it in other ways...
  • unfortunately JavaScript dates are a little wonky in some browsers: officially it needs to support ISO8601 (and i think RFC2822 is by convention) Source: MDN, but non-standard formats tend to be browser dependent, as @Dorival mentioned below MomentJS is very commonly used instead of the built in Date because it offers a standard way to represent Datetimes cross browser, and it supports more formats than Date does (it's also pretty good at guessing given a non-standard format)
  • output will be 1576410945000 in console panel of browser.
  • This question already has an accepted answer (almost) identical to this.