本文介绍了在Google AppScript中获取今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Google appscript上获取今天"日期?
How do I get the Today date on google appscript?
我需要编写代码以在单元格中输入今天的日期.
I need to write a code to input today´s date in a cell.
function changeDate(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(GA_CONFIG);
var date = //Today´s date!?!?!!?
var endDate = date;
sheet.getRange(5, 2).setValue(endDate);
}
推荐答案
Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")
您可以通过交换值来更改格式.
You can change the format by doing swapping the values.
- dd =天(31)
- MM =月(12)-区分大小写
- yyyy =年(2017)
function changeDate() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(GA_CONFIG);
// You could use now Date(); on its own but it will not look nice.
var date = Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")
var endDate = date
}
这篇关于在Google AppScript中获取今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!