Google Apps Script formatDate using user's time zone instead of GMT

后端 未结 1 1965
一个人的身影
一个人的身影 2020-12-06 04:43

I have a line that sets the current date and time in a cell:

sheet.getRange(1,1).setValue(new Date());

Then I have a line that creates a f

相关标签:
1条回答
  • 2020-12-06 05:23

    You can directly get the spreadsheet Time Zone like this :

      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 you want to choose it yourself :

    http://joda-time.sourceforge.net/timezones.html

    0 讨论(0)
提交回复
热议问题