我将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(伦敦)。
我错过了什么?
答案 0 :(得分:1)
这种情况正在发生,因为时间以UTC格式返回。您需要将它们转换为您当地的时间。有一个非常好的名为moment.js的库。您可以使用该库使用以下代码:
var localTime = moment.utc(startDate).toDate();
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');