Google Script App-通过脚本在特定日期和时间创建触发器

发布于 2025-01-21 05:12:54 字数 1763 浏览 0 评论 0原文

我需要使用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!!!!

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原野 2025-01-28 05:12:54

https://developers.google.com/apps-script/参考/脚本/clock-trigger构建器

日期功能将在该日期午夜运行,它将不允许指定时间。

时间的唯一选择是使用

// Creates a trigger that runs 10 minutes later
ScriptApp.newTrigger("myFunction")
  .timeBased()
  .after(10 * 60 * 1000)
  .create();

您可以修改时间以满足您的需求。

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

// Creates a trigger that runs 10 minutes later
ScriptApp.newTrigger("myFunction")
  .timeBased()
  .after(10 * 60 * 1000)
  .create();

You can modify the time to fit your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文