繁体   English   中英

在午夜更新完整的日历日

[英]Updating Full Calendar Day At Midnight

    //Reset At Midnight
function resetAtMidnight() {
    var now = new Date();
    var night = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate() + 1, // the next day, ...
        0, 0, 0 // ...at 00:00:00 hours
    );
    var msToMidnight = night.getTime() - now.getTime();

    setTimeout(function() {
        reset();              //      <-- This is the function being called at midnight.
        resetAtMidnight();    //      Then, reset again next midnight.
    }, msToMidnight);
}


function reset() {
     $('#calendar').fullCalendar('today');
}     

我试图让 FullCalendar.js 每天午夜更新当天。 我从这里的另一篇文章中提取了这个重置片段 - 但重置功能似乎没有执行。

你没有提供完整的细节,所以我不知道你到底需要什么,但下面的代码可能会帮助你解决你的问题。

您可以使用moment.js库轻松查看午夜。 以下代码取自另一篇文章检测午夜和重置数据的最佳方法

 $(document).ready(function() { var midnight = "0:00:00"; var now = null; setInterval(function() { now = moment().format("H:mm:ss"); if (now === midnight) { alert('reset() function here'); } $("#time").text(now); }, 1000); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <code id="time"></code>

完全控制:

您可以根据需要使用rerenderEventsrefetchEvents 所以它会是这样的

function reset(){
    $('#calendar').fullCalendar('rerenderEvents');
OR

    $('#calendar').fullCalendar('refetchEvents');
}

如果您想重新绘制完整控件,那么这里是另一篇内容丰富的帖子“ 重新绘制完整日历

正如帖子所建议的那样,你可以做

$('#calendar').fullCalendar('destroy');
$('#calendar').fullCalendar('render');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM