Google Sheets API v4 inserting new Date() in datet

2019-07-22 03:20发布

The following code inserts new Date() as Mon Sep 04 21:34:54 GMT+01:00 2017

Using Google Sheets API v4, Sheets.Spreadsheets.Values.update

function withUpdate() {
    var spreadsheetId = "someSpreadsheetId";
    var request = {
        majorDimension: "ROWS",
        values: [[new Date()]]
    };
    Sheets.Spreadsheets.Values.update(
      request,
      spreadsheetId,
      "Sheet1!BW20",
      {valueInputOption: "USER_ENTERED"}
    );
}

The following code inserts new Date() as 04.09.2017 21:34:54

Using Google Apps Script, getRange().setValue

function withSetValue () {
  var spreadsheet = SpreadsheetApp.openById("someSpreadsheetId")
  var sheetOne = spreadsheetId.getSheetByName("Sheet1");
  sheetOne.getRange(20, 75).setValue(new Date());
}

Is it possible to make [i.e. Google Sheets API v4] to insert new Date() the same way as Google Apps Script inserts it in the following format: 04.09.2017 21:34:54? How to avoid getting this format Mon Sep 04 21:34:54 GMT+01:00 2017 with Values.update?

Thank you.

1条回答
Animai°情兽
2楼-- · 2019-07-22 03:58

Found the answer to own question by using:

Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yy HH:mm:ss");
查看更多
登录 后发表回答