【问题标题】:How to use .setTimeZone(String) in Google Apps Script如何在 Google Apps 脚本中使用 .setTimeZone(String)
【发布时间】:2019-07-07 22:08:34
【问题描述】:

我已经使用 Google Apps 脚本将所有学校课程转移到日历中,但我遇到了夏令时问题。 我找到了

.setTimeZone(string)

在 Google 文档中,但无法使其正常工作。 有什么帮助吗?

function makeCalendar(name, begin, end, calendar, recurrence) {
    var eventSeries = CalendarApp.getCalendarById(calendar).createEventSeries(
        name,
        begin,
        end,
        recurrence.setTimeZone("Europe/Belgrade")
    );  
}

这应该改变了事件的时区,但它停留在 UTC,我可以手动编辑,但不能通过代码更改它

【问题讨论】:

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


    【解决方案1】:

    您似乎在reoccurance 变量上调用.setTimeZone("Europe/Belgrade"),而不是在CalendarApp.createEventSeries() 链上。

    function makeCalendar(name, begin, end, calendar, recurrence) {
        var eventSeries = CalendarApp.getCalendarById(calendar).createEventSeries(
            name,
            begin,
            end,
            recurrence
        ).setTimeZone("Europe/Belgrade");  //Call on chain, not on reoccurence.
    }
    

    【讨论】:

    • 重复规则
    【解决方案2】:

    我玩了一段时间,我认为更改日历时区做到了,现在可以了,但我不知道为什么

    我不知道这对你有用,但我只是这样做了

    CalendarApp.getCalendarById(calendar).setTimeZone(string)
    

    【讨论】:

    • 这不是我发布的答案吗?时区显然应该匹配。
    • 不,你说我需要在事件结束时添加它,这是不正确的,首先它给出错误,其次事件没有问题,while 日历是,但仍然感谢您的尝试
    • 你能用代码更新你的答案,以便未来的用户有一个具体的答案吗?
    猜你喜欢
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    相关资源
    最近更新 更多