Home >Web Front-end >JS Tutorial >Solution to the problem that IE browser does not support NEW DATE() with parameters in javascript_javascript tips

Solution to the problem that IE browser does not support NEW DATE() with parameters in javascript_javascript tips

WBOY
WBOYOriginal
2016-05-16 17:55:391435browse
Copy code The code is as follows:

var date1=new Date(dateTimes[z][1]);

The time can be obtained normally under Firefox, but it is NaN under IE7. After struggling for a long time, I gave up on new date and then found a piece of code in a foreigner's forum that could be compatible with the formatted date code of all browsers:
Copy code The code is as follows:

function NewDate(str) {
str = str.split('-');
var date = new Date();
date.setUTCFulYear(str[0], str[1] - 1, str[2]);
date.setUTCHours(0, 0, 0, 0);
return date;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn