我试图在此示例中设置时区,当选择日历上的时间时,尽管将timezone
选项设置为'America/new_york',但显然仍在UTC中:
$(document).ready(() => {
const fc = $('#c');
const tz = 'America/New_York';
const data = {
meetings: [
{
title: 'Test data',
start: 1513976400000,
end: 1513980000000
}
]
};
const myEvents = [];
for (let d = 0; d < data.meetings.length; d += 1) {
myEvents.push({
title: 'Booked',
start: (moment(data.meetings[d].start).tz(tz)),
end: (moment(data.meetings[d].end).tz(tz)),
});
fc.fullCalendar({
events: myEvents,
timezone: tz,
header: {
left: 'title',
center: 'month,agendaWeek',
right: 'today prev,next',
},
selectable: true,
selectHelper: true,
select(start, end) {
alert(`Book a meeting for ${start.format('h:mma on dddd M/D')}?`);
},
selectOverlap: false,
editable: false,
eventOverlap: false,
});
});
任何人都可以确认这是错误或用户错误吗?
将默认时刻区更改为必需的时区(以下是工作 示例更改时区并观察日历上的事件)。
$(function () {
var timeZone = 'America/New_York';
var now = moment().add(moment.tz(timeZone).utcOffset(), "m");
moment.tz.setDefault(timeZone);
$('#calendar').fullCalendar({
header: {
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: 'https://fullcalendar.io/demo-events.json',
defaultView: 'agendaWeek',
timeFormat: 'HH:mm',
editable: true,
});
});
<script src="https://momentjs.com/downloads/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://jakubroztocil.github.io/rrule/lib/rrule.js"></script>
<script src="https://momentjs.com/downloads/moment-timezone-with-data.js"></script>
<link href="https://fullcalendar.io/js/fullcalendar-3.0.1/fullcalendar.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.0.1/fullcalendar.js"></script>
<div id="calendar"></div>