【问题标题】:Google App Script Calendar API - createAllDayEvent() method not working as expectedGoogle App Script Calendar API - createAllDayEvent() 方法未按预期工作
【发布时间】:2011-07-06 09:28:48
【问题描述】:

我已经打开了一个 issue 关于(我认为)是 Google App Scripts 中的一个错误,但它看起来没有受到监控,所以我想知道是否有人可以解决我的问题。

总之,我正在运行一个脚本(通过谷歌电子表格),它试图在我创建的谷歌日历中添加一个条目。

function testCalendarAllDayEvent(){
  var calendar = CalendarApp.getCalendarById("od4434jhedv936p65gcbl3bjg@group.calendar.google.com");
  var calTimezone = calendar.getTimeZone();
  var scriptTimezone = Session.getTimeZone();
  var calendarevent = calendar.createAllDayEvent("Test Event", new Date(2011,7,1));
  var summary = calendarevent.getStartTime();
}

所以上面的代码在 2011 年 7 月 31 日而不是 7 月 1 日添加了“测试事件”。如果我将其更改为 new Date (2011,7,2)它是在 2011 年 8 月 1 日发布的。所以似乎还有 30 天。 我查看时区以确保它们相同的原因。当我查看summary 变量值时,它是Mon Aug 01 2011 01:00:00 GMT+0100 (IST)

我不想盲目地在所有日期上加上 30 天,因为它只会以眼泪结束。有谁知道我在做什么是不正确的?我使用 Google 示例作为模板。

【问题讨论】:

    标签: google-calendar-api google-apps-script


    【解决方案1】:

    这里的问题是Date constructor 采用从零开始的月份索引。所以

    new Date(2011,7,1) 创建日期为 2011 年 8 月 1 日。

    new Date(2011,6,1) 创建日期为 2011 年 7 月 1 日。

    【讨论】:

    • 抱歉这么久才回复,但我正在处理其他事情。感谢您的回答,但这不是解决方案,因为 calendar.createAllDayEvent("Testt123t", new Date(2011,7,1)) 在 2011 年 6 月 29 日而不是 2011 年 8 月 1 日创建事件。
    猜你喜欢
    • 2019-10-28
    • 2017-10-24
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多