FullCalendar来自Office365的日期偏移
问题描述:
我正在将事件从Office365导入到FullCalendar以显示在网站上,但显示的时间与Office365上的事件设置的时间偏移1小时(即事件设置为14:00:00为被显示为13:00:00),我被卡住了,无法弄清楚为什么会发生这种情况。FullCalendar来自Office365的日期偏移
功能创建日历事件:日历
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');
实际导入数据的开始/结束时间是什么样子的?他们是否有指定的时区? – ADyson
他们来这样的:2017-05-26T12:00:00.0000000,我正在修剪额外的零,你可以看到代码。 –
它可能与它现在在英国的夏季时间有关,所以时钟比UTC早一个小时。 https://www.timeanddate.com/worldclock/converted.html?iso=20130911T160009&p1=0&p2=136 Office365可能会显示BST时间?检查导出的数据与Office屏幕上实际显示的内容,并且这些日期也没有指定任何可能混淆事件的时区。 – ADyson