Home > Mobile >  Google Scripts: retrieving time from CalendarEvent
Google Scripts: retrieving time from CalendarEvent

Time:03-07

Good morning to all, I have some troubles retrieving timestamp from CalendarEvent of my Calendars. Consider I'm a beginner on Google Scripts so maybe I don't see a very simple bug in my code..

The Calendar from which I'm trying to retrieve my events has Timezone setup with GMT 0100 Central European Time. The events scheduled in this calendar also has this Timezone..

But when I call the method

myEvent.getStartTime();

the timezone displayed is: -0500 Eastern Standard Time

Following you can see log from Google Logger:

9:12:47 AM  Info    Timezone calendario: Europe/Rome
9:12:47 AM  Info    titolo: Assenza AGO
9:12:47 AM  Info    start time: Fri Mar 04 2022 03:00:00 GMT-0500 (Eastern Standard Time)
9:12:47 AM  Info    end time: Fri Mar 04 2022 12:00:00 GMT-0500 (Eastern Standard Time)

Consider that the actual time set on the event is: March 4th, 2022 09:00:00.

Where's the mistake in my code? :)

Any suggestion would be appreciated, thank you.

Leonardo

CodePudding user response:

Did you change your time zone on google script manifest file?

if not: On the left side of the page, go to Settings, check 'Show "appsscript.json" manifest file in editor' Then on the files you would see a appsscript.json, change the time zone for your script.

If you have set your time zone for your script correctly and that does not work. Then use Utilities.formatDate function to change time zone.

console.log(myEvent.getStartTime(),'GMT  0100',"yyyy-MM-dd'T'HH:mm:ss'Z'"))

You can change time zone , and the format at the 2nd and 3rd arguments.

  • Related