IE浏览器(js)new Date()带参返回NaN解决方法
function myNewDate(str) {
if(!str){
return 0;
}
arr=str.split(" ");
d=arr[0].split("-");
t=arr[1].split(":");
var date = new Date(d[0],d[1]-1,d[2],t[0],t[1],t[2]);
//date.setUTCFullYear(d[0], d[1] - 1, d[2]);
// date.setUTCHours(t[0], t[1], t[2], 0);
return date;
}
//倒计时interval = setInterval(getRTime,1000);
//调用函数
function getRTime(){
//var EndTime= new Date('2019-10-21 18:35:00'); //截止时间
var EndTime='';
//获取倒计时截止日期
var countDownStr = $("#countDownTime").val();
if(countDownStr !=null && countDownStr !=""){
EndTime = myNewDate(countDownStr)
}else{
return ;
}
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
/*var d=Math.floor(t/1000/60/60/24);
t-=d*(1000*60*60*24);
var h=Math.floor(t/1000/60/60);
t-=h*60*60*1000;
var m=Math.floor(t/1000/60);
t-=m*60*1000;
var s=Math.floor(t/1000);*/
var d=Math.floor(t/1000/60/60/24);
var h=Math.floor(t/1000/60/60%24);
var m=Math.floor(t/1000/60%60);
var s=Math.floor(t/1000%60);
if(s < 0){
clearInterval(interval);
interval=null;
document.getElementById("t_d").innerHTML = 0 + "天";
document.getElementById("t_h").innerHTML = 0 + "时";
document.getElementById("t_m").innerHTML = 0 + "分";
document.getElementById("t_s").innerHTML = 0 + "秒";
return ;
}
document.getElementById("t_d").innerHTML = d + "天";
document.getElementById("t_h").innerHTML = h + "时";
document.getElementById("t_m").innerHTML = m + "分";
document.getElementById("t_s").innerHTML = s + "秒";
}