Reputation: 5871
I have the following date 21:50:04 Nov 13, 2017 PST
as String, I'm using the following piece of code to format it (to show only month and day).
Utilities.formatDate(new Date(inData[r][0]), "GMT", 'MMM-dd')
The output I'm getting is Nov-14
, I have tried changing the zone to GMT-05:00
which was still producing the same result.
Can anyone tell me what is the change I have to do so that it will return Nov-13
for the same input.
Upvotes: 1
Views: 1191
Reputation: 31320
You can't use the semicolon in the time zone:
You must use GMT-500
The time zone setting for Utilities.formatDate()
is very finicky.
Because the time zone of GMT-05:00 is invalid, it resorts back to GMT which is time zone 0000.
Upvotes: 2
Reputation: 11278
Inside the Script editor, go to File > Project properties and ensure that the timezone is set to PST.
Also, since the input is in PST, you should use the same timezone for the output as well.
var date = new Date("Nov 13, 2017 21:50:04");
Logger.log(date);
Logger.log(Utilities.formatDate(date, "PST", 'MMM-dd'))
Upvotes: 5