用于构建时钟触发器的构建器。
方法
| 方法 | 返回值类型 | 简介 |
|---|---|---|
after(durationMilliseconds) | Clock | 指定触发器在当前时间之后运行的最短时长(以毫秒为单位)。 |
at(date) | Clock | 指定触发器的运行时间。 |
at | Clock | 指定触发器在给定日期触发,默认情况下在午夜前后(+/- 15 分钟)。 |
at | Clock | 指定触发器运行的小时。 |
create() | Trigger | 创建触发器。 |
every | Clock | 指定每 n 天运行一次触发器。 |
every | Clock | 指定每 n 小时运行一次触发器。 |
every | Clock | 指定每 n 分钟运行一次触发器。 |
every | Clock | 指定每 n 周运行一次触发器。 |
in | Clock | 指定触发器运行时指定日期/时间所采用的时区。 |
near | Clock | 指定触发器运行的分钟(加或减 15 分钟)。 |
on | Clock | 指定触发器运行的月份日期。 |
on | Clock | 指定触发器运行的星期几。 |
详细文档
after(durationMilliseconds)
指定触发器在当前时间之后运行的最短时长(以毫秒为单位)。实际时长可能会有所不同,但不会低于您指定的最短时长。
// Creates a trigger that runs 10 minutes later ScriptApp.newTrigger('myFunction').timeBased().after(10 * 60 * 1000).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
duration | Integer | 触发器应在当前时间之后运行的最短时长(以毫秒为单位)。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
at(date)
指定触发器的运行时间。
// Creates a trigger for December 1, 2012 const triggerDay = new Date(2012, 11, 1); ScriptApp.newTrigger('myFunction').timeBased().at(triggerDay).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
date | Date | 一个 Date 对象,表示触发器应运行的时间。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
atDate(year, month, day)
指定触发器在给定日期触发,默认情况下在午夜前后(+/- 15 分钟)。
// Schedules for January 1st, 2013 ScriptApp.newTrigger('myFunction').timeBased().atDate(2013, 1, 1).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
year | Integer | 用于安排触发器的日历年。 |
month | Integer | 用于安排触发器的日历月(应为介于 1 到 12 之间的数字, 含 1 和 12)。 |
day | Integer | 用于安排触发器的日历日(应为介于 1 到 31 之间的数字, 含 1 和 31)。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
atHour(hour)
指定触发器运行的小时。
// Runs between 5am-6am in the timezone of the script ScriptApp.newTrigger('myFunction') .timeBased() .atHour(5) .everyDays( 1) // Frequency is required if you are using atHour() or nearMinute() .create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
hour | Integer | 触发的小时。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
create()
everyDays(n)
指定每 n 天运行一次触发器。
ScriptApp.newTrigger('myFunction').timeBased().everyDays(3).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
n | Integer | 执行之间相隔的天数。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
everyHours(n)
指定每 n 小时运行一次触发器。
ScriptApp.newTrigger('myFunction').timeBased().everyHours(12).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
n | Integer | 执行之间相隔的小时数。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
everyMinutes(n)
指定每 n 分钟运行一次触发器。n 必须为 1、5、10、15 或 30。
ScriptApp.newTrigger('myFunction').timeBased().everyMinutes(10).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
n | Integer | 执行之间相隔的分钟数。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
everyWeeks(n)
指定每 n 周运行一次触发器。
ScriptApp.newTrigger('myFunction') .timeBased() .everyWeeks(2) .onWeekDay(ScriptApp.WeekDay.FRIDAY) .create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
n | Integer | 执行之间相隔的周数。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
inTimezone(timezone)
指定触发器运行时指定日期/时间所采用的时区。默认情况下,时区是脚本的时区。
有效时区字符串列表与 Joda.org 列出的有效时区字符串相对应。无效的时区字符串会导致脚本抛出错误。
// Schedule the trigger to execute at noon every day in the US/Pacific time zone ScriptApp.newTrigger('myFunction') .timeBased() .atHour(12) .everyDays(1) .inTimezone('America/Los_Angeles') .create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
timezone | String | 用于处理事件中的时间信息的时区。 |
返回
ClockTriggerBuilder - 用于链式调用的 ClockTriggerBuilder。
nearMinute(minute)
指定触发器运行的分钟(加或减 15 分钟)。如果未调用 nearMinute(),则会使用随机分钟值。
// Runs at approximately 5:30am in the timezone of the script ScriptApp.newTrigger('myFunction') .timeBased() .atHour(5) .nearMinute(30) .everyDays( 1) // Frequency is required if you are using atHour() or nearMinute() .create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
minute | Integer | 触发的分钟。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
onMonthDay(day)
指定触发器运行的月份日期。
// Schedules for the first of every month ScriptApp.newTrigger('myFunction').timeBased().onMonthDay(1).create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
day | Integer | 应安排触发器的月份日期。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。
onWeekDay(day)
指定触发器运行的星期几。
ScriptApp.newTrigger('myFunction') .timeBased() .onWeekDay(ScriptApp.WeekDay.FRIDAY) .create();
参数
| 名称 | 类型 | 说明 |
|---|---|---|
day | Weekday | 触发的星期几。 |
返回
ClockTriggerBuilder - 用于链式调用的构建器。