Google Script App-通过脚本在特定日期和时间创建触发器
我需要使用Google脚本创建一个在特定日期和时间运行的触发器(格式Yyyy-MM-DD HH:MM)。 由于我的脚本,将触发器列为“触发面板”,并在适当的日期安排,但根本没有启动。 如果我在相同的数据时间内手动编码触发器,则在到期时开始。
以下是我的测试的示例:
function TriggerTest()
{
var newDate = new Date().setMinutes(new Date().getMinutes() + 1440) //next day to start trigger
var newYYYY = new Date(newDate).getFullYear();
var newMM = new Date(newDate).getMonth();
var newDD = new Date(newDate).getDate();
var newHH = 06; //Hour start trigger
var newMI = 50; //Minute start trigger
//Example 1 - date, time (using valueOf)
var strTimerTrigger = new Date(newYYYY,newMM,newDD,newHH,newMI,00,000000).valueOf();
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(strTimerTrigger)).create();
//Example 2 - date, time (using valueOf)
var strTimerTrigger = new Date(newYYYY,newMM,newDD,newHH,newMI).valueOf();
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(strTimerTrigger)).create();
//Example 3 - date, time (using parameters)
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(newYYYY, newMM, newDD,
13, 30)).create();
//Example 4 - date, time (using hard code)
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(2022, 03, 12, 13, 50)).create();
//Example 5 - date, time (using string)
ScriptApp.newTrigger("DummyTrigger").timeBased().at("2022-04-12 14:00").create();
//Example 6 -
const dummy = new Date(2022, 03, 12, 14, 15);
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(dummy)).create();
//Example 7
ScriptApp.newTrigger("DummyTrigger").timeBased().at((dummy)).create();
}
任何建议? 预先感谢!!!
I need to create a trigger running at a specific date and time (format YYYY-MM-DD HH:MM) with google script.
As result of my script, trigger is listed into "Trigger Panel" and scheduled at right date time but not starts at all.
If I code manually the trigger, with same data time, it starts when due.
Here are examples of my tests:
function TriggerTest()
{
var newDate = new Date().setMinutes(new Date().getMinutes() + 1440) //next day to start trigger
var newYYYY = new Date(newDate).getFullYear();
var newMM = new Date(newDate).getMonth();
var newDD = new Date(newDate).getDate();
var newHH = 06; //Hour start trigger
var newMI = 50; //Minute start trigger
//Example 1 - date, time (using valueOf)
var strTimerTrigger = new Date(newYYYY,newMM,newDD,newHH,newMI,00,000000).valueOf();
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(strTimerTrigger)).create();
//Example 2 - date, time (using valueOf)
var strTimerTrigger = new Date(newYYYY,newMM,newDD,newHH,newMI).valueOf();
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(strTimerTrigger)).create();
//Example 3 - date, time (using parameters)
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(newYYYY, newMM, newDD,
13, 30)).create();
//Example 4 - date, time (using hard code)
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(2022, 03, 12, 13, 50)).create();
//Example 5 - date, time (using string)
ScriptApp.newTrigger("DummyTrigger").timeBased().at("2022-04-12 14:00").create();
//Example 6 -
const dummy = new Date(2022, 03, 12, 14, 15);
ScriptApp.newTrigger("DummyTrigger").timeBased().at(new Date(dummy)).create();
//Example 7
ScriptApp.newTrigger("DummyTrigger").timeBased().at((dummy)).create();
}
Any suggestions?
Thanks a lot in advance!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
https://developers.google.com/apps-script/参考/脚本/clock-trigger构建器
日期功能将在该日期午夜运行,它将不允许指定时间。
时间的唯一选择是使用
您可以修改时间以满足您的需求。
https://developers.google.com/apps-script/reference/script/clock-trigger-builder
at date function will run at midnight on that date, it will not allow to specify the time.
The only option for time is to use
You can modify the time to fit your needs.