Unknown Javascript date between Firefox and everyone else

Does anyone know why in Firefox, if you execute the code below, it will check it as a date if the string is passed in four numbers and only four numbers? In every other browser that I tested with (IE, Chrome), it will always return as not a date.

Being that the specification, as Marcel Corpel points out below, states that it should return to using spam specific to the implementation of Firefox, I really wonder why Firefox is dropping, shows this anomaly.

function isDate(sDate) {  
    var temp = new Date(sDate);  
    if (temp.toString() == "NaN" || temp.toString() == "Invalid Date") {  
        alert("Not a Date");  
    } else {  
        alert("Is a Date!");  
    }
}
+5
source share
4 answers

Date, , parse (IETF- RFC 1123) (: MDC). .

, , (, 0 (= )) , 1 1970 00:00:00 UTC.

:, ,

var a = new Date('0123');
console.log(a);

Fri Jan 01 0123 01:00:00 GMT+0100 (CET)

Firefox, -, '0123' .

2: , MDC Date.parse :

JavaScript 1.8.5, ISO 8601 .

ISO 8601 ( "" ):

:
(, 1997)
    :
- (, 1997-07)
    :
-- (, 1997-07-16)

, ISO 8601, , , .

+4

javascript. javascript.

  • , .
  • , , . - , Date:)
+1

This works in all browsers -

new date ('2001/01/31 12:00:00 AM')

+1
source

I ran into the same problem as this in firefox, for some reason I canโ€™t explain any four-digit numeric characters are a valid date in FF, in other browsers it's NaN:

A bit of a nasty job for FF, but it worked for me:

function isDate(sDate) {  
    if(sDate.match(/^\d{4}$/))
       return false;
    var temp = new Date(sDate);  
    if (temp.toString() == "NaN" || temp.toString() == "Invalid Date") {  
        alert("Not a Date");  
    } else {  
        alert("Is a Date!");  
        return true;  
    }
}
0
source

All Articles