我正在尝试创建一个时差函数。我需要能够判断 CookieTime 是否被粘贴。我尝试了很多不同的事情,但似乎无法让它发挥作用。关于为什么这不会减去有什么建议吗?
我昨晚在帮助下成功完成了 DateDiff:Javascript DateDiff
我的控制台中的错误是:Uncaught TypeError: Object 12:34:00 has no method 'getTime' 不知道我是否明白这意味着什么。
CookieTime = "12:34:00"; //Cookie time...
currTime = "05:11:55"; //Current Real Time...
function past(){
//Print the results for testing...
document.write(CookieTime + '<br>'); // = 12:34:00
document.write(currTime + '<br/>'); // = 05:11:55
// = Testing the results here = NaN
document.write(CookieTime.getTime() - currTime.getTime() + '<br/>');
if (CookieTime - currTime >= 0){
// Time has pasted!!
return true;
} else {
// Time is not here yet!!
return false;
}
}
document.write(past()); //Print response.
最佳答案
您需要解析原始日期:
CookieTime = new Date('1970-1-1 12:34:00'); //Cookie time...
currTime = new Date('1970-1-1 05:11:55'); //Current Real Time...
关于javascript - 减法时间 = NAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12017409/