javascript - Google Apps Script formatDate using user's time zone instead of GMT -
i have line sets current date , time in cell:
sheet.getrange(1,1).setvalue(new date());
then have line creates formatted date based on cell's value:
var addeddate = sheet.getrange(1,1).getvalue(); var addedtime = utilities.formatdate(addeddate, "gmt", "hh:mm a");
the resulting addedtime seems in gmt time zone , need in user's time zone. eastern time (-0500), if subtract 5 hours time doesn't account daylight saving time (-0400).
i checked documentation formatdate here: https://developers.google.com/apps-script/reference/utilities/utilities#formatdate(date,string,string)
which links official java simpledateformat class documentation here: http://docs.oracle.com/javase/6/docs/api/java/text/simpledateformat.html
... can't find list of valid time zones there replace gmt with.
you can directly spreadsheet time zone :
var addeddate = sheet.getrange(1,1).getvalue(); var addedtime = utilities.formatdate(addeddate, spreadsheetapp.getactive().getspreadsheettimezone(), "hh:mm a");
see doc here
but google apps script uses these formats if want choose :
Comments
Post a Comment