Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌应用程序脚本:时间驱动触发时区问题_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 谷歌应用程序脚本:时间驱动触发时区问题

Javascript 谷歌应用程序脚本:时间驱动触发时区问题,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我正试图在GoogleApps脚本中构建一个基本的时间驱动触发器,以便在指定的日期和时间运行函数 我的代码如下: function createTimeDrivenTriggers() { ScriptApp.newTrigger('myFunction') .timeBased() .atDate(2019, 12, 29) .atHour(12) .nearMinute(5) .create(); Logger.log("Trigger started

我正试图在GoogleApps脚本中构建一个基本的时间驱动触发器,以便在指定的日期和时间运行函数

我的代码如下:

function createTimeDrivenTriggers() {
ScriptApp.newTrigger('myFunction')
    .timeBased()
    .atDate(2019, 12, 29)
    .atHour(12)
    .nearMinute(5)
    .create();
Logger.log("Trigger started!");
}

function myFunction() {
  Logger.log("I was triggered!");
}
但是,每次尝试运行createTimeDrivenTriggers函数时,都会出现以下错误:

You cannot schedule an event in the past. (line 7, file "Triggers")
在撰写本文时,2019-12-29 12:05不是过去(在我的时区)。这让我觉得脚本运行的时区与我不同。。是这样吗?如果是,如何将脚本设置为默认用户时区


这个脚本是Google Sheets插件的一部分,我确认我的Google Sheets时区设置为我的本地时区。

这个答案如何?不幸的是,
atDate
atHour
不能同时使用。在您的情况下,将使用
atDate
,并尝试将触发器安装为
2019-12-29 00:00
。这样就出现了这样的错误

当您想为
2019-12-29 12:05
安装时间驱动触发器时,如何进行如下修改

修改脚本: 发件人: 致: 注:
  • 在这种情况下,请使用12月份的
    11
    。因为日期的月份初始索引为
    0

    monthIndex:表示月份的整数值,从1月的0开始到12月的11

参考资料:

如果这不是你想要的方向,我道歉。

这个答案怎么样?不幸的是,
atDate
atHour
不能同时使用。在您的情况下,将使用
atDate
,并尝试将触发器安装为
2019-12-29 00:00
。这样就出现了这样的错误

当您想为
2019-12-29 12:05
安装时间驱动触发器时,如何进行如下修改

修改脚本: 发件人: 致: 注:
  • 在这种情况下,请使用12月份的
    11
    。因为日期的月份初始索引为
    0

    monthIndex:表示月份的整数值,从1月的0开始到12月的11

参考资料:
如果这不是你想要的方向,我道歉

ScriptApp.newTrigger('myFunction')
    .timeBased()
    .atDate(2019, 12, 29)
    .atHour(12)
    .nearMinute(5)
    .create();
ScriptApp.newTrigger("myFunction")
    .timeBased()
    .at(new Date(2019, 11, 29, 12, 5))
    .create();