我将事件从Office365导入FullCalendar中以显示在网站上,但是显示的时间与Office365上事件的设置时间相比有1小时的偏移(即,设置为14:00:00的事件显示为13:00:00 ),我很困惑,无法弄清为什么会这样。
为日历创建事件的函数:
function getTentativeEvents(){
client
.api("/me/calendars/"+calID1+"/calendarview/?$top=3000&$filter=ShowAs eq 'Tentative'&startDateTime="+calStartDate+"&endDateTime="+calEndDate)
.select("Subject,Start,Id,End,Categories")
.get((err, res) => {
if (err) {
console.log(err);
return;
}
console.log(res);
var catNameFound = "";
var categoryTitleTotal = timeSlotsCategoryTitleArray.length;
var arrayLength = res['value'].length;
var counter = arrayLength -1;
for (var i = 0; i < arrayLength; i++) {
var eveColour = defaultTimeSlotBackgroundColour;
var eveTxtColour = defaultTimeSlotTextColour;
var categoriesLength = res['value'][i]['categories'].length;
if(categoriesLength >= 1){
for (var i2 = 0; i2 < categoriesLength; i2++) {
var catNameFound = res['value'][i]['categories'][i2];
catNameFound = catNameFound.toLowerCase();
for (var i3 = 0; i3 < categoryTitleTotal; i3++) {
var timeSlotToCheck = timeSlotsCategoryTitleArray[i3];
timeSlotToCheck = timeSlotToCheck.toLowerCase();
//console.log(catNameFound);
if(timeSlotToCheck == catNameFound){
eveColour = timeSlotsBackgroundColourArray[i3];
eveTxtColour = timeSlotsTextColourArray[i3];
}
}
}
}
eventSubject = res['value'][i]['subject'];
eventID = res['value'][i]['id'];
startDate = res['value'][i]['start']['dateTime'];
endDate = res['value'][i]['end']['dateTime'];
startDate = startDate.replace(".0000000", "");
endDate = endDate.replace(".0000000", "");
addToEventList(eventSubject,startDate,endDate,eventID,eveColour,eveTxtColour);
}
//
$('#calendar1').fullCalendar('gotoDate', '<?php echo $theDateAfter; ?>');
$("#calendar1").fullCalendar('addEventSource', timeSlotsArray);
$('#calendarLoader').hide();
$('#calendar1').show();
});
以及日历的参数:
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
defaultView: 'agendaDay',
defaultDate: '<?php echo $theDateAfter; ?>',
eventColor: defaultTimeSlotBackgroundColour,
minTime: "10:00:00",
timezone: "Europe/London",
ignoreTimezone: false,
maxTime: "20:00:00",
editable: false
我检查了Office365上的设置,并将其正确设置为UTC +0(伦敦)。
我想念什么?
最佳答案
之所以发生这种情况,是因为时间是以UTC返回的。您需要将它们转换为当地时间。有一个非常好的库,称为moment.js。您可以使用该库使用以下代码:
var localTime = moment.utc(startDate).toDate();
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');
关于javascript - 从Office365的FullCalendar日期偏移,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44160975/