Run trigger at specific date and time

我是研究僧i 提交于 2020-08-11 07:30:26

问题


I want to run a trigger at specific date and time (+or - 15 min).

I have a date min string with YYYY-MM-DD HH:MM format say 2017-04-01 18:05 How will I modify the below script to run at 18 hours and 5 minutes.

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

回答1:


You can try this:

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




回答2:


// 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();

I'm pretty sure that the month in the constructor is zero-based (January==0), so, I changed the 04 to a 3.



来源:https://stackoverflow.com/questions/43157709/run-trigger-at-specific-date-and-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!