Javascript 如何创建自动包含日期的便笺?

Javascript 如何创建自动包含日期的便笺?,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我想看看在便条中自动获取日期的方法,以便进行跟进 // Add the date when you create a note function Notes() { var app= SpreadsheetApp; var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); // Returns the active shee var activeRange= activeSheet.getActiveRa

我想看看在便条中自动获取日期的方法,以便进行跟进

// Add the date when you create a note

function Notes() 
{
   
  var app= SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); // Returns the active shee
  var activeRange= activeSheet.getActiveRange() // Returns the active Range
  
  activeRange.setNote(Date());  // Set the date in the note


  
}
此代码正在工作,但我得到的信息是:周四10月22日2020 08:28:09 GMT+0200中欧夏季时间
例如,我只想获得2020年10月22日08:28:09。

在JS中打印a有很多方法

var d=新日期 console.logd.toString console.logd.toISOString console.logd.toDateString console.logd.togmString console.logd.toutString console.logd.toTimeString console.logd.toLocaleString console.logd.toLocaleDateString
console.logd.toLocaleTimeString有很多方法可以在JS中打印

var d=新日期 console.logd.toString console.logd.toISOString console.logd.toDateString console.logd.togmString console.logd.toutString console.logd.toTimeString console.logd.toLocaleString console.logd.toLocaleDateString
console.logd.toLocaleTimeString您只需将日期转换为所需的格式dd/MM/yyyy HH:MM:ss。您可以使用来实现以下目标:

function Notes() 
{
  var app= SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); // Returns the active shee
  var activeRange= activeSheet.getActiveRange() // Returns the active Range
  var today = Utilities.formatDate(new Date(), app.getActive().getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm:ss");
  
  activeRange.setNote(today);  // Set the date in the note
}

您只需要将日期转换为所需的格式dd/MM/yyyy HH:MM:ss。您可以使用来实现以下目标:

function Notes() 
{
  var app= SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); // Returns the active shee
  var activeRange= activeSheet.getActiveRange() // Returns the active Range
  var today = Utilities.formatDate(new Date(), app.getActive().getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm:ss");
  
  activeRange.setNote(today);  // Set the date in the note
}

但我希望在注释中看到这一点,而不是在控制台日志中。谢谢你的帮助!只需将日期替换为activeRange.setNoteDate中所需的格式,我这样做了,但它不起作用。activeRange.setNoted.getFullYear+/+d.getMonth+1+/+d.getDate+TM提前感谢,但我希望在备注中看到,而不是控制台日志中。谢谢你的帮助!只需将日期替换为activeRange.setNoteDate中所需的格式,我这样做了,但它不起作用。activeRange.setNoted.getFullYear+/+d.getMonth+1+/+d.getDate+TM提前感谢