Rather than defining the timeZone as GMT (or GMT+1 for daylight savings) in the 'formatDate' property, I will be starting to use 'getScriptTimeZone' when it is not bound to a Google sheet. This eliminates the issue of the script becoming inaccurate by 1 hour when the clocks go back/forward, as it will pick up the time zone from when/where the script is being run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getScriptTimeZone() { | |
// get script time zone of location where being run | |
var timeZone = Session.getScriptTimeZone(); | |
// create a new date variable | |
var newDate = new Date(); | |
// format the new date variable as required | |
var niceDate = Utilities.formatDate(newDate, timeZone, "dd_MM_YYYY HH:mm:ss"); | |
// log output | |
Logger.log(niceDate); | |
} |
No comments:
Post a Comment