The new date ("XXXX") method is often required when we need to convert a string of date strings into a specific date format.
At that time, under IE browser, you will encounter this problem:
New Date ('2016-01-01 00:00:00') // returns this value invalid date, conversion failed
But this method can return the correct results on Google Chrome.
Workaround: The final discovery is that the format of the string is not caused by some browsers failing.
New Date (' 2016/01/01 00:00:00 ') //
When used in a specific way, you can convert the date string to the correct format by using some string conversions, and then use the new Date ().
var date= "2016-12-12 10:10:10";d ate=date.replace (/-/, "/"); Date D=new date (date);
So, there are different browsers, and the following list shows how all browsers support it.
1 varD =NewDate (2011, 01, 07);//yyyy, MM-1, DD2 varD =NewDate (2011, 01, 07, 11, 05, 00);//yyyy, MM-1, DD, hh, MM, SS3 varD =NewDate ("02/07/2011");//"Mm/dd/yyyy"4 varD =NewDate ("02/07/2011 11:05:00");//"Mm/dd/yyyy hh:mm:ss"5 varD =NewDate (1297076700000);//milliseconds6 varD =NewDate ("Mon-Feb-11:05:00 GMT");//"Day Mon dd yyyy hh:mm:ss GMT/UTC
Solve the problem of invalid date for the value of new date () for IE, Firefox browser JS