Js date object compatibility handling method

  • 2020-03-30 01:33:40
  • OfStack


function NewDate(str) { str = str.split('-'); 
var date = new Date(); 
date.setUTCFullYear(str[0], str[1] - 1, str[2]);
 date.setUTCHours(0, 0, 0, 0); 
return date;
 }

So, in order to ensure compatibility in all browsers, in fact, in order to be compatible with Internet explorer, we should use the Date() object in the same way

New Date(year, month, day, hour, minute, SEC, millsec)

or

New Date(millsec)(millsec is the number of milliseconds since January 1, 1970).

The result returned under ie when new Date ("" Date text"") is a special Date object, except that the ie debugger displays it as NaN, and a call to it to return number returns NaN


Related articles: