时间触发月末
Time trigger end of months
因为月末从 30 到 31 不等,我必须设置一个时间触发器来触发另一个函数。如果我输入所有月份的 31 号,它会在 30 号工作吗?
这是我的代码
function timerTrigger() {
ScriptApp.newTrigger('codeTrigger')
.timeBased()
.onMonthDay(31)
.atHour(23)
.inTimezone('Indian/Mauritius')
.create()
}
此函数将为您计算每个月的天数。
function timerTriggerForLastDayInCurrentMonth() {
ScriptApp.newTrigger('codeTrigger')
.timeBased()
.onMonthDay(daysInThisMonth())
.atHour(23)
.inTimezone('Indian/Mauritius')
.create()
}
function daysInThisMonth() {
const m = new Date().getMonth();//calculate the month for current date which is Jan - Dec 0 - 11
return new Date(new Date().getFullYear(), m + 1, 0).getDate();//add 1 to the month and set the day of the month to zero and it gives the number of days in the previous month which is the current month since one was added to it
}
因为月末从 30 到 31 不等,我必须设置一个时间触发器来触发另一个函数。如果我输入所有月份的 31 号,它会在 30 号工作吗?
这是我的代码
function timerTrigger() {
ScriptApp.newTrigger('codeTrigger')
.timeBased()
.onMonthDay(31)
.atHour(23)
.inTimezone('Indian/Mauritius')
.create()
}
此函数将为您计算每个月的天数。
function timerTriggerForLastDayInCurrentMonth() {
ScriptApp.newTrigger('codeTrigger')
.timeBased()
.onMonthDay(daysInThisMonth())
.atHour(23)
.inTimezone('Indian/Mauritius')
.create()
}
function daysInThisMonth() {
const m = new Date().getMonth();//calculate the month for current date which is Jan - Dec 0 - 11
return new Date(new Date().getFullYear(), m + 1, 0).getDate();//add 1 to the month and set the day of the month to zero and it gives the number of days in the previous month which is the current month since one was added to it
}