Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Time 仅在部分时间间隔内运行触发器_Time_Google Apps Script_Triggers - Fatal编程技术网

Time 仅在部分时间间隔内运行触发器

Time 仅在部分时间间隔内运行触发器,time,google-apps-script,triggers,Time,Google Apps Script,Triggers,我使用这部分代码(以及时间触发器)在“工作时间”每5分钟运行一次脚本,但现在我需要一些调整 function officeHours(){ var nowH=new Date().getHours(); var nowD=new Date().getDay(); Logger.log('day : '+nowD+' Hours : '+nowH) if(nowH>17||nowH<8||nowD==6||nowD==0){return} Browser.msgBox('time

我使用这部分代码(以及时间触发器)在“工作时间”每5分钟运行一次脚本,但现在我需要一些调整

function officeHours(){
var nowH=new Date().getHours();
var nowD=new Date().getDay();
Logger.log('day : '+nowD+'   Hours : '+nowH)
if(nowH>17||nowH<8||nowD==6||nowD==0){return}
Browser.msgBox('time to work !');//normally your real function should begin here...
}
功能办公时间(){
var nowH=新日期().getHours();
var nowD=新日期().getDay();
Logger.log('day:'+nowD+'Hours:'+nowH)

如果(nowH>17 | | nowH,您可以检查当前小时是否在本例中的轮班时间之间

function officeHours(startShift, endShift){
  startShift = startShift || 23;
  endShift = endShift || 7;
  var currentHour = new Date().getHours();
  if (startShift > endShift) {
    if (currentHour >= startShift || currentHour <= endShift) {
      // run the trigger function
    } 
  } else {
    if (currentHour >= startShift && currentHour <= endShift) {
      // run the trigger function
    } 
  }
}
功能办公时间(开始换档、结束换档){
startShift=startShift | | 23;
endShift=endShift | | 7;
var currentHour=新日期().getHours();
如果(开始换档>结束换档){
如果(当前小时>=开始换档| |当前小时=开始换档和当前小时