我在Javascript中执行函数,如VisualBasic DateDiff.
你给两个日期和返回的时间间隔(秒,分钟,天等...)
DateDiff(ByVal Interval As Microsoft.VisualBasic.DateInterval, _
ByVal Date1 As Date, ByVal Date2 As Date) as Long
Run Code Online (Sandbox Code Playgroud)
那么计算Javascript日期差异的最佳方法是什么?
我正在尝试创建一个时差功能.我需要能够判断CookieTime是否被粘贴.我尝试过很多不同的东西,似乎无法让它发挥作用.为什么这不会减去任何建议?
我昨晚在帮助下成功完成了DateDiff:Javascript DateDiff
我的控制台中的错误是:未捕获TypeError:对象12:34:00没有方法'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.
Run Code Online (Sandbox Code Playgroud) javascript ×2