简体   繁体   中英

Google Sheets API v4 inserting new Date() in datetime format

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 [ie 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.

通过使用以下命令找到了自己问题的答案:

Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yy HH:mm:ss");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM