时钟触发器的构建器。
方法
方法 | 返回类型 | 简介 |
---|---|---|
after(durationMilliseconds) | ClockTriggerBuilder | 指定触发器当前运行时间之后的最短时长(以毫秒为单位)。 |
at(date) | ClockTriggerBuilder | 指定触发器的运行时间。 |
atDate(year, month, day) | ClockTriggerBuilder | 指定触发器在指定日期触发,默认情况下靠近午夜(+/- 15 分钟)。 |
atHour(hour) | ClockTriggerBuilder | 指定触发器运行的小时数。 |
create() | Trigger | 创建触发器。 |
everyDays(n) | ClockTriggerBuilder | 指定每 n 天运行一次触发器。 |
everyHours(n) | ClockTriggerBuilder | 指定每 n 小时运行一次触发器。 |
everyMinutes(n) | ClockTriggerBuilder | 指定每 n 分钟运行一次触发器。 |
everyWeeks(n) | ClockTriggerBuilder | 指定每 n 周运行一次触发器。 |
inTimezone(timezone) | ClockTriggerBuilder | 指定触发器运行时指定日期/时间的时区。 |
nearMinute(minute) | ClockTriggerBuilder | 指定触发器运行的分钟(正负 15 分钟)。 |
onMonthDay(day) | ClockTriggerBuilder | 指定触发器运行的月份中的日期。 |
onWeekDay(day) | ClockTriggerBuilder | 指定触发器在星期几运行。 |
详细文档
after(durationMilliseconds)
指定触发器当前运行时间之后的最短时长(以毫秒为单位)。 实际时长可能会有所不同,但不会低于您指定的最短时长。
// Creates a trigger that runs 10 minutes later ScriptApp.newTrigger("myFunction") .timeBased() .after(10 * 60 * 1000) .create();
参数
名称 | 类型 | 说明 |
---|---|---|
durationMilliseconds | Integer | 在当前时间之后触发器应运行的最短时长(以毫秒为单位)。 |
弃踢回攻
ClockTriggerBuilder
- 用于链接的构建器。
at(date)
指定触发器的运行时间。
// Creates a trigger for December 1, 2012 var 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
- 用于链接的构建器。