new Date 在IE 下 兼容性的问题
2013-04-11 17:24
183 查看
问题 : new Date(string) 在IE下不兼容,返回NaN
解决办法: :用 new Date(year,month,day,hour,minute,millseconds)
使用例子 如下:
/*
* 选择最近时间段自动同步到起止时间
*/
function syncDateAuto(curObj){
var beginDate , endDate , curDate = new Date();
var chooseDate = $(curObj).val();
if(chooseDate === "0"){ // 今天
beginDate = curDate;
}else if(chooseDate === "1"){ // 最近7天
beginDate = new Date(curDate.getTime() - 7 * 24 * 60 * 60 * 1000);
}else if(chooseDate === "2"){ // 最近1个月
var year = curDate.getFullYear();
var month = curDate.getMonth() - 1;
var day = curDate.getDate();
beginDate = new Date(year,month,day,00,00,00);
}else if(chooseDate === "3"){
var year = curDate.getFullYear();
var month = curDate.getMonth() - 3;
var day = curDate.getDate();
beginDate = new Date(year,month,day,00,00,00);
}
$("#searchBeginDate").val(beginDate.Format("yyyy-MM-dd"));
$("#searchEndDate").val(curDate.Format("yyyy-MM-dd"));
}
再看看老外的回复:
解决办法: :用 new Date(year,month,day,hour,minute,millseconds)
使用例子 如下:
/*
* 选择最近时间段自动同步到起止时间
*/
function syncDateAuto(curObj){
var beginDate , endDate , curDate = new Date();
var chooseDate = $(curObj).val();
if(chooseDate === "0"){ // 今天
beginDate = curDate;
}else if(chooseDate === "1"){ // 最近7天
beginDate = new Date(curDate.getTime() - 7 * 24 * 60 * 60 * 1000);
}else if(chooseDate === "2"){ // 最近1个月
var year = curDate.getFullYear();
var month = curDate.getMonth() - 1;
var day = curDate.getDate();
beginDate = new Date(year,month,day,00,00,00);
}else if(chooseDate === "3"){
var year = curDate.getFullYear();
var month = curDate.getMonth() - 3;
var day = curDate.getDate();
beginDate = new Date(year,month,day,00,00,00);
}
$("#searchBeginDate").val(beginDate.Format("yyyy-MM-dd"));
$("#searchEndDate").val(curDate.Format("yyyy-MM-dd"));
}
再看看老外的回复:
2 down vote accepted | Looking to the documetation the right format is the following: new Date(year, month, day [, hour, minute, second, millisecond ]) So if you run the following code it will be fine in all browsers: var myDate= new Date(1985, 01, 01 , 00, 06, 00, 0000000000); myDate // you get the right date in all browsers IE8/7 included |
相关文章推荐
- new Date() 在 ie 浏览器中兼容性的问题
- IE8和IE7下js的兼容性问题
- li value 为负值时,IE 的兼容性问题
- 如何解决QTP与ie兼容性问题?可能有以下几种原因造成。
- IE与FireFox的兼容性问题
- 解决 IE 6/7 中console对象兼容性问题
- FF和IE下的js兼容性问题 作者:w3pop.com 翻译/整理:w3pop.com
- JavaScript在IE和FF下的兼容性问题解决方案
- CSS hack IE常见兼容性问题
- 在IE11和Firefox下attr和prop的兼容性问题(IE低版本和google没有问题)
- IE与FireFox的兼容性问题及解决 (zt)
- Javascript的IE和Firefox兼容性问题
- IE与FF脚本兼容性问题
- IE和火狐的css兼容性问题
- JS兼容性问题(FF与IE)
- ie兼容性问题,以及js书写习惯。
- IE兼容性问题
- 关于J-UI DWZ富框架在IE10下兼容性问题
- IE7.JS解决IE兼容性问题方法
- 一些Javascript的IE和Firefox(火狐)兼容性的问题总结及常用例子