fullcallendar v4 info.event.start显示的时间与日历中显示的时间不同



Calendar(fullcalendar v4(显示从数据库读取并调整到所需时区的具有适当时间的事件。

我在12.00到14.00之间显示了事件。

日历初始化的一部分:

calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid', 'timeGrid', 'interaction' ],
allDaySlot: false,
selectable: true,
timeZone: '<?php echo $calendar_timezone ?>',
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
defaultView: 'timeGridWeek',
nowIndicator: true,
slotDuration: '<?php echo $calendar_full_hours_only ?>',
businessHours: {
startTime: '08:00',
endTime:   '19:00',
daysOfWek:[1,2,3,4,5]
},
}

JSON提要很好。事件在日历网格中正确显示:

[
{
"id": 53,
"title": "Test Event 12.00 - 14.00",
"start": "2019-11-19 12:00",
"end": "2019-11-19 14:00",
"allDay": 0,
"editable": 1
}
]

单击时会显示不同的时间。

eventClick: function(info) {
console.log('Id: ' + info.event.id);
console.log('Start: ' + info.event.start);
console.log('End: ' + info.event.end);
console.log('Calendar timezone: ' + '<?php echo $calendar_timezone ?>');
console.log('Browser timezone: ' + Intl.DateTimeFormat().resolvedOptions().timeZone);
}

控制台中的输出为:

Id: 53
Start: Fri Nov 19 2019 13:00:00 GMT+0100 (czas środkowoeuropejski standardowy)
End: Fri Nov 19 2019 15:00:00 GMT+0100 (czas środkowoeuropejski standardowy)
Calendar timezone: Europe/Warsaw
Browser timezone: Europe/Warsaw

比日历上显示的时间晚了一个小时。

更重要的是,如果我将日历的时区更改为另一个时区,它会更正日历中显示的事件的时间,但如果我再次单击它们,它会在一小时后显示时间。不知道发生了什么。

我刚刚发现,如果我点击空插槽,问题不会发生。那么时间是正确的。只有当我单击现有事件时才会发生这种情况。

问题出现在fullcalendar和Bootstrap 4 Datetimepicker之间的交互中,后者将从fullcalendary事件读取的所有日期视为UTC时间。将Moments时区添加到fullcalendar和Datetimepicker中解决了这个问题。

最新更新