问题
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