2017-06-28 37 views
0

我想在FullCalendar中的America/New_York時間顯示一個事件。我可以彈出一個彈出窗口來顯示正確的日期/時間,但FullCalendar會將開始和結束時間修改爲本地時區,而不管我的設置如何。作爲一個例子,我有一個事件集於6月30日早上12點,當我調整我的本地時區到中央時間時,我在控制檯看到「開始」被修改爲6月29日晚上11點。謝謝!FullCalendar不遵守指定的時區

function(result, event){ 
if (event.status) { 
    var rightNow = moment.tz("America/New_York"); 
    $.each(result,function(){ 
    this.start = moment.tz(this.Event_Time__c, "America/New_York"); 
    this.StartDate = this.start; 
    this.end = moment.tz(this.Event_Time__c, "America/New_York"); 
    this.EndDate = this.end; 
    this.Status = this.Event_Display_Status__c; 
    var day = moment.tz(this.Event_Time__c, "America/New_York").format("DD"); 
    var isWeekend = (day == 6) || (day == 0); // 6 = Saturday, 0 = Sunday 
    var isPast = (rightNow > moment.tz(this.Event_Time__c, "America/New_York")); 
    this.isPast = isPast; 
    if (isPast) { 
     this.Event_Display_Status__c = 'Event Passed'; 
     this.Status = 'Event Passed'; 
    } 
    resultOut.push(this); 
    }); 
    initFullCalendar(resultOut); 
} 
else{ 
    alert(event.message); 
} 
} 

function initFullCalendar(calendarEntries){ 
    $('#calendarx').empty(); 
    $('#calendarx').fullCalendar({ 
     timezone: 'America/New_York', 
     editable: false, 
     weekends: true, 
     eventSources: [{ 
       events: calendarEntries 
     }] 
    }); 
} 

回答

0

在你的初始化,設置以下選項:

{ timezone: "local" } 

這並不意味着本地的計算機,而是當地提供的Date對象。

在未來中的數據,設置確保該偏移設置像這樣:

{ title: "event1", start: "2017-06-28T15:00:00-04:00" } 

對於美國/紐約它應該是-04:00或-05:00取決於日光節約和確切的位置。

另一個技巧是提供一個日期,沒有任何在所有的偏移量( 「2017-06-28T15:00:00」),那麼你的時區INI選項設置爲:

{ timezone: "America/New_York" } 

多見於:https://fullcalendar.io/docs/timezone/timezone/