Home > Web Front-end > JS Tutorial > body text

javascript中IE浏览器不支持NEW DATE()带参数的解决方法_javascript技巧

WBOY
Release: 2016-05-16 17:55:39
Original
1356 people have browsed it
复制代码 代码如下:

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

在火狐下 可以正常取得时间,在IE7下 却是 NaN。纠结老长时间,放弃了new date 然后再老外的论坛中找了一段段代码可以兼容所有浏览器的格式化日期代码:
复制代码 代码如下:

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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!