2

我正在尝试创建一个时差函数。而且我需要能够判断是否粘贴了 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.
4

1 回答 1

7

您需要解析原始日期:

CookieTime = new Date('1970-1-1 12:34:00'); //Cookie time...
currTime   = new Date('1970-1-1 05:11:55'); //Current Real Time...
于 2012-08-18T09:20:29.580 回答