写了一个倒计时,原代码如下:
var times = new Date();
var timesout = new Date("2016-6-7");
var timesg = times.getTime();
var timeoutg = timesout.getTime();
var timescha = parseFloat(timeoutg) - parseFloat(timesg);
var days = Math.floor(timescha/1000/60/60/24);
var timesmins = timescha%(24*3600*1000);
var timeshouer=Math.floor(timesmins/(3600*1000))
$('.time-day').text(days);
$('.time-hour').text(timeshouer);
结果在谷歌浏览器上看是没问题的,但是在上线调试后,发现在ie浏览器上显示NAN,肿木办呢?
去网上找了半天,各种parseFloat,没有用。于是自己试。
解决办法很简单:
var times = new Date();
var timesout = new Date("2016/6/7 00:00:00");
var timesg = times.getTime();
var timeoutg = timesout.getTime();
var timescha = parseFloat(timeoutg) - parseFloat(timesg);
var days = Math.floor(timescha/1000/60/60/24);
var timesmins = timescha%(24*3600*1000);
var timeshouer=Math.floor(timesmins/(3600*1000))
$('.time-day').text(days);
$('.time-hour').text(timeshouer);
其实就是把日期的格式从2007-02-02 变成了2007/02/02 就是这么简单~~~