当我创建一个事件然后通过 Google 脚本访问它时,我注意到 endTime 超出了我设置事件的实际日期。当在日历中迭代几天以获取事件时,这可能会非常有问题。
示例:进入 Google 日历并使用今天日期的标准默认值设置全天事件。然后执行以下代码:
function foo() {
var cal = CalendarApp.getDefaultCalendar();
var date = new Date();
var events = cal.getEventsForDay(date);
Logger.log("Events for today: "+date);
for (var i=0; i<events.length;i++) {
Logger.log(events[i].getTitle());
Logger.log(" "+events[i].getStartTime());
Logger.log(" "+events[i].getEndTime());
}
date.setDate(date.getDate()+1);
Logger.log("\nEvents for tomorrow: "+date);
events = cal.getEventsForDay(date);
for (var i=0; i<events.length;i++) {
Logger.log(events[i].getTitle());
Logger.log(" "+events[i].getStartTime());
Logger.log(" "+events[i].getEndTime());
}
}
示例输出(来自 Google 脚本日志):
Events for today: Wed Jul 04 2012 19:39:12 GMT+0200 (CEST)
Test
Wed Jul 04 2012 02:00:00 GMT+0200 (CEST)
Thu Jul 05 2012 02:00:00 GMT+0200 (CEST)
Events for tomorrow: Thu Jul 05 2012 19:39:12 GMT+0200 (CEST)
Test
Wed Jul 04 2012 02:00:00 GMT+0200 (CEST)
Thu Jul 05 2012 02:00:00 GMT+0200 (CEST)
OK