Reputation: 1
Good Morning, I am using the code below that someone lovingly provided online, to create "backups" or copies of a google sheet each night. The issue is that the timestamp is in GMT and I really need it to be in EST (New York). Can someone please tell me how to fix this? I am a total novice
Link to original: https://gist.github.com/abhijeetchopra/99a11fb6016a70287112
ISSUE AREA: generates the timestamp and stores in variable formattedDate as year-month-date hour-minute-second var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss");
I tired typing EST, typing -5:00, the time did not correct.
Upvotes: 0
Views: 610
Reputation: 136
You were on the right track, typing "EST" or "-5:00" didn't do anything because they're not the format Utilities.formatDate()
is looking for.
As per this answer you need to use formats available here.
This should achieve what you're after:
Utilities.formatDate(new Date(), "US/Eastern", "yyyy-MM-dd' 'HH:mm:ss");
or
Utilities.formatDate(new Date(), "America/New_York", "yyyy-MM-dd' 'HH:mm:ss");
Note that "GMT"
worked originally as it is listed as an alias on the formats page, but EST is not.
Further Reading
google ads scripting documentation on dates, but should be mostly transferrable!
Upvotes: 0