Reputation: 4871
How can you set the current time with google app scripts? I'm having a tough time finding the Time documentation.
I'm able to get the time in milliseconds using.
(new Date()).getTime()
I'd like to now format this time as 11:56 AM. I'm using the Date documentation. I've tried using toLocaleTimeString()
from javascript but it is not defined in app scripts
Upvotes: 0
Views: 4421
Reputation: 7387
For formatting a date, what you want is the Utilities.formatDate() function, documented here: https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)
Usage to get the time only would be:
Utilities.formatDate(YOUR DATE,YOUR TIMEZONE, 'HH:mm')
replacing YOUR DATE and YOUR TIMEZONE with the appropriate values.
Upvotes: 1