Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsgoogle-apps

How to format the time in this Google Apps Script?


I want to format a Google Sheet cell when I read it in my script but it comes out 25 minutes later. The cell's time is 20:00:00 but the output is "20:25". I am using this

var formattedDate = Utilities.formatDate(dataRow[9], "GMT+2", HH:mm");

Without using it the time comes as "1899-12-30T18:25:08.000Z" even though the cell's content is 20:00:00. Any ideas how to remove the extra 25 minutes?


Solution

  • Use the Spreadsheet's time zone settings.

    var formattedDate = Utilities.formatDate(dataRow[9], SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "HH:mm");