I'm a new user for Google apps script, I meet a question recently. In Google apps script, I want to set a trigger to run the app on 9:00AM every day. But I can only set a trigger by Trigger-Add a trigger, set a trigger 9:00-10:100 AM every day,But I found that it run my program about 9:30 every day. So my question is how set a trigger on 9:00 AM every day? Thank you very much..
问题:
回答1:
As far as I know, the "Add a trigger" feature will only let you set triggers within this one hour range.
You can, however, set a narrower time range if you create your trigger programmatically (using the ClockTriggerBuilder class). It'll still have a thirty minute range, though: the app run will run at 9am plus or minus 15 minutes. Is that close enough for you or do you need it to run at 9am sharp?
It would go like this:
ScriptApp.newTrigger('YourFunction')
.timeBased()
.everyDays(1)
.atHour(9)
.create();
Here you can find more information
回答2:
if it must run precisely at a given time, your only option is to create a trigger that runs every minute, and first thing checks if its the correct time to run.
to check if its time, save the last run time in a script property and compare with the current time.
all other methods will give you a delay of a few minutes, even if you set the trigger to run at a specific time.