设置定时触发器的时区 [英] Setting the Timezone for timed triggers

查看:168
本文介绍了设置定时触发器的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个利用Google定时触发器的脚本。但是,在正确的时间让剧本触发时遇到问题。我住在悉尼(格林威治标准时间+10),每天中午都需要脚本开火。



我已经进入并在电子表格设置中设置了时区,项目属性以及Google云端硬盘的全局设置,但尽管如此,脚本并没有在正确的时间触发。它已经关闭了大约6-5小时。更令人沮丧的是,当我进入触发器管理面板的时区被列为太平洋时间(-8小时),并且由于这是不够的每隔一段时间我登录它似乎改变到一些其他随机时间很快就像东部标准等(在触发器面板内)。



我甚至尝试过手动补偿时差,但这也没有奏效,理想情况下不是路径我想下降,因为它会影响剧本触发的那一天(它将在EST时间的星期一和星期二在悉尼),这会影响我正在运行的DB查询,这是对日期敏感的。



无论哪种方式,我现在已经画出了一个空白,想不到任何进一步的解决方案。我该如何解决这个问题?

解决方案

我也有这个问题。可能是因为我在旅行。设置电子表格的时区无济于事。设置脚本的时区也没有帮助。



使用@ Rodrigo脚本的修改版本有什么帮助:

  function addTrigger(){
// main()将在周一16:00在指定时区每周调用
var everyWeek = ScriptApp.newTrigger(main)
.timeBased()
.everyWeeks(1)
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.inTimezone(America / Los_Angeles)
.atHour(16)
.create();您可以使用 .inTimezone()来指定时区。您可以使用 .inTimezone()来指定时区。 - 请参阅此处


运行此脚本后,您可以使用GUI编辑器编辑触发器。此外,现在时区对于我使用GUI添加的新触发器是正确的 - 不确定是因为脚本还是因为我现在回家了。

I've written a script that utilizes Google's timed triggers. However, I'm having problems getting the script to fire at the correct time. I reside in Sydney (GMT +10) and need the script to fire at noon each day.

I've gone in and set the timezone in the Spreadsheets settings, the Project Properties as well as the global settings for Google Drive but despite all this the script doesn't fire at the right time. It's off by about 6-5 hrs. What is even more frustrating is when I go into the triggers admin panel the timezone is listed as Pacific time (-8hrs) and as that wasn't enough every other time I log on it seem to change to some other random time soon like Eastern standard etc. (within the triggers panel that is).

I've even tried manually compensating for the time difference but that hasn't worked either and it's ideally not the path I want to go down as it affects the day which the script is triggered (it will be Monday in EST time and Tuesday here in Sydney) which has impacts on the DB query I'm running which is date sensitive.

Either way, I've now drawn a blank can't think of any further solutions. How can I address this?

解决方案

I had this problem as well. Possibly because I was traveling. Setting the spreadsheet's timezone didn't help. Setting the script's timezone didn't help either.

What did help was using a modified version of @Rodrigo's script:

function addTrigger() {
  // main() will be called weekly on Monday at 16:00 in the specified time zone
  var everyWeek = ScriptApp.newTrigger("main")
      .timeBased()
      .everyWeeks(1)
      .onWeekDay(ScriptApp.WeekDay.MONDAY)
      .inTimezone("America/Los_Angeles")
      .atHour(16)
      .create();
}

You can specify the timezone using .inTimezone() -- see description here.

Once you run this script, you can edit the trigger using the GUI editor. Also, now the timezone is correct for new triggers I add using the GUI -- not sure if that's because of the script or because I'm back home now.

这篇关于设置定时触发器的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆