//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>
完全控制:
您可以根据需要使用 rerenderEvents 或 refetchEvents。所以它会是这样的
function reset(){
$('#calendar').fullCalendar('rerenderEvents');
OR
$('#calendar').fullCalendar('refetchEvents');
}
如果您想重新绘制完整控件,那么这是另一个内容丰富的帖子"重新绘制完整日历"
正如帖子建议的那样,您可以做到
$('#calendar').fullCalendar('destroy');
$('#calendar').fullCalendar('render');