在特定日期和时间运行触发器

时间:2017-04-01 13:50:35

标签: date google-apps-script triggers google-sheets google-docs

我想在特定日期和时间(+或 - 15分钟)运行触发器。

我有一个日期最小字符串YYYY-MM-DD HH:MM格式说 2017-04-01 18:05 如何修改以下脚本以便在18小时5分钟运行

 var triggerDay = new Date(2017, 04, 01);
 ScriptApp.newTrigger("myFunction")
   .timeBased()
   .at(triggerDay)
   .create();

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

function createTimeDrivenTriggers() {
// Trigger on 2017-04-01 around 18:00 (±15 min).
ScriptApp.newTrigger('myFunction')
    .timeBased()
    .atDate(2017, 04, 01)
    .atHour(18)
    .create();
}

https://developers.google.com/apps-script/reference/script/clock-trigger-builder

答案 1 :(得分:0)

Order date: 2020-07-08 12:00, days: 1, expected: 2020-07-09 - OK
Order date: 2020-07-08 12:00, days: 2, expected: 2020-07-10 - OK
Order date: 2020-07-08 18:00, days: 1, expected: 2020-07-10 - OK
Order date: 2020-07-08 12:00, days: 6, expected: 2020-07-16 - OK
Order date: 2020-07-08 12:00, days: 5, expected: 2020-07-15 - OK

我非常确定构造函数中的// the full Date constructor is: // new Date( year, month, day, hour, min, sec, ms ) var triggerDay = new Date(2017, 3, 01, 18, 5); ScriptApp.newTrigger("myFunction") .timeBased() .at(triggerDay) .create(); 是基于零的(一月== 0),因此,我将month更改为04