Getting wrong time and time zone in Trigger

523 views
Skip to first unread message

Irfan Khan

unread,
Aug 6, 2022, 2:38:09 PM8/6/22
to Google Apps Script Community

I am facing one issue, I am trying to programmatically create a few apps script triggers which should run at a specific time, everything looks good when I check the logs but when the trigger adds it shows the wrong time zone and time Here is the code:-

items.forEach((r,i)=> 
  var timeCon = r.split(":").map(r=> parseInt(r)) 
  var date = new Date(currentDate) 
  var hour = timeCon[0]-1 var min = timeCon[1] 
  var year = date.getFullYear() 
  var month = date.getMonth() 
  var day = date.getDay() 
  console.log(new Date(year,month,day,hour,min)) 
  let t_ID = ScriptApp.newTrigger("currentTIme").timeBased().inTimezone('Europe/Amsterdam').at(new Date(year,month,day,hour,min)).create().getUniqueId() 
 triggers.push([r,t_ID]) 
 })

Here is the Logs I get in the console(Correct Time zone and Data Time):-

Logs

This is what I get when I open one of the triggers, every trigger has the same time, another unusual thing to notice

Trigger

My project setting and manifest file also have the correct time zone, please guide me on what I am doing wrong, or if there is another way to achieve this.

Just to add, I am actually in GMT+5:30 time zone.


CBMServices Web

unread,
Aug 6, 2022, 2:51:22 PM8/6/22
to google-apps-sc...@googlegroups.com
There are two timezones you should check to ensure they are set correctly.

There is one in the script manifest. Open manifest and ensure it is set to correct timezone that you want. If your script is in a container (spreadsheet or doc), then check the timezone in the spreadsheet. You can set a timezone for a spreadsheet so that times are shown correctly.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/be588d0a-d707-45d9-8b9e-30cf473cfeccn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages