jquery图书馆知道新的一天即将来临

Kha*_*ham 0 javascript jquery datetime

我想知道如何通过使用jquery或来检测或知道新的一天何时到来others jquery library.

举些例子:

假设,现在是2016/06/23 23:59:50.当second来到2016/06/24 00:00:00,jquery可以检测event.

我知道我们可以在新的一天到来时使用setTimeOutsetInterval检查每一秒.

但我不想使用上面的这些方法,我们检测到什么方法的jquery?

Bar*_*mar 6

日期更改时没有触发自动事件.您可以做的是计算日期更改之前的时间,并setTimeout在发生这种情况时用于运行函数.

var now = new Date;
var midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
setTimeout(function() {
    alert("It's tomorrow!");
}, midnight.getTime() - now.getTime());
Run Code Online (Sandbox Code Playgroud)

参数new Date()是日期和时间的组成部分.省略时间参数将它们全部默认为0.因此,在日期中添加1并省略时间将返回下一个午夜的时间.