我已经为这个问题苦苦挣扎了好几个星期了。我已经想出了如何让它在客户端中工作,这样一个新事件就可以在任何时区显示而无需任何服务器调用。
您需要包含四个时刻的时区插件,2 个来自时刻站点,2 个来自完整日历站点。
https://codepen.io/alexgrant999/pen/gOOWLdb?editors=0010
document.addEventListener('DOMContentLoaded', function() {
var initialTimeZone = 'UTC';
var timeZoneSelectorEl = document.getElementById('time-zone-selector');
var loadingEl = document.getElementById('loading');
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'momentTimezone','interaction', 'dayGrid', 'timeGrid', 'list' ],
timeZone: initialTimeZone,
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
navLinks: true, // can click day/week names to navigate views
editable: true,
selectable: true,
eventLimit: true, // allow "more" link when too many events
events: 'https://fullcalendar.io/demo-events.json',
select: function(info)
{
thestart = calendar.addEvent({
title: "Session",
//constraint: 'businessHours',
start: info.start,
end: info.end
});
},
loading: function(bool) {
if (bool) {
loadingEl.style.display = 'inline'; // show
} else {
loadingEl.style.display = 'none'; // hide
}
},
eventTimeFormat: { hour: 'numeric', minute: '2-digit', timeZoneName: 'short' }
});
calendar.render();
// load the list of available timezones, build the <select> options
// it's highly encouraged to use your own AJAX lib instead of using enter code hereFullCalendar's internal util
FullCalendar.requestJson('GET', 'https://fullcalendar.io/demo-timezones.json', {}, function(timeZones) {
timeZones.forEach(function(timeZone) {
var optionEl;
if (timeZone !== 'UTC') { // UTC is already in the list
optionEl = document.createElement('option');
optionEl.value = timeZone;
optionEl.innerText = timeZone;
timeZoneSelectorEl.appendChild(optionEl);
}
});
}, function() {
// failure
});
// when the timezone selector changes, dynamically change the calendar option
timeZoneSelectorEl.addEventListener('change', function() {
calendar.setOption('timeZone', this.value);
});
});