0

我正在使用腳本將Google日曆中的活動下載到電子表格中。我有一個問題,即「全天事件」進入2天,例如:5/9/17的全天事件以5/9/17-5/10/17的形式下載到表單中。 這裏是我的代碼:爲什麼每一天的活動都代表2天的活動?

// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2) 
for (var i=0;i<events.length;i++) { 
    var row=i+2; 
    var myformula_placeholder = ''; 
    // Matching the "header=" entry above, this is the detailed row entry "details=", 
    // and must match the number of entries of the GetRange entry below 
    // NOTE: I've had problems with the getVisibility for some older events not having a value, 
    // so I've had do add in some NULL text to make sure it does not error 
    var details=[[ 
    events[i].getStartTime(), 
    events[i].getTitle(), 
    events[i].getAllDayStartDate(), 
    events[i].getAllDayEndDate(), 
    events[i].getLocation(), 
    events[i].getDescription(), 
    events[i].getId() 
    ]]; 
    var range=sheet.getRange(row,1,1,7); 
    range.setValues(details); 
} 

任何想法可能發生在這裏?這是一個錯誤還是在我的代碼中有錯誤?我想一個解決方法可能是從每個AllDayEndDate號碼中減去1天,但不知道爲什麼這甚至發生在第一位。

+0

如您所見,成功調用事件方法將返回包含[開始日期和結束日期](https://developers.google.com/google-apps/calendar/v3/reference/events#resource)的響應在事件資源中。 – noogui

回答

0

按照documentation這是正常的行爲:

獲取關於此全天日曆事件結束的日期。 (如果這是 不是全天事件,則此方法將拋出異常。) 返回日期將代表在一天開始時的午夜 事件在腳本的時區結束後。要改用日曆的 時區,請調用getEndTime()。