简体   繁体   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');
}     

I am trying to have FullCalendar.js update the current day everyday at midnight.我试图让 FullCalendar.js 每天午夜更新当天。 I pulled this reset snippet from another post on here - but the reset function does not seem to execute.我从这里的另一篇文章中提取了这个重置片段 - 但重置功能似乎没有执行。

You have not provided full detail so I don't know what exactly you need but following code might help you to solve your issue.你没有提供完整的细节,所以我不知道你到底需要什么,但下面的代码可能会帮助你解决你的问题。

You can check midnight quite easily using moment.js library.您可以使用moment.js库轻松查看午夜。 Following code was taken from another post Best Way to detect midnight and reset data以下代码取自另一篇文章检测午夜和重置数据的最佳方法

 $(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>

Fullcontrol:完全控制:

You can either use rerenderEvents or refetchEvents as per your requirement.您可以根据需要使用rerenderEventsrefetchEvents So it will be something like this所以它会是这样的

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

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

If you want to re-draw the fullcontrol then here is another informative post ' re-draw fullcalendar '如果您想重新绘制完整控件,那么这里是另一篇内容丰富的帖子“ 重新绘制完整日历

As post suggested you can do正如帖子所建议的那样,你可以做

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

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

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