Google apps script DateTime格式化3个月
以下代码以这种格式返回日期-2014年3月21日 我们需要它以这种格式返回日期-2014年3月21日。三个字母的文本名称。当前时间很好,但不是关键时间。需要做哪些改变Google apps script DateTime格式化3个月,google-apps-script,datetime-format,Google Apps Script,Datetime Format,以下代码以这种格式返回日期-2014年3月21日 我们需要它以这种格式返回日期-2014年3月21日。三个字母的文本名称。当前时间很好,但不是关键时间。需要做哪些改变 function onOpen() { var ui = DocumentApp.getUi(); // Or FormApp or SpreadsheetApp. ui.createMenu('Custom Menu') .addItem('Insert Date', 'insertDate')
function onOpen() {
var ui = DocumentApp.getUi();
// Or FormApp or SpreadsheetApp.
ui.createMenu('Custom Menu')
.addItem('Insert Date', 'insertDate')
.addToUi();
}
function insertDate() {
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
// Attempt to insert text at the cursor position. If insertion returns null,
// then the cursor's containing element doesn't allow text insertions.
var d = new Date();
var dd = d.getDate();
dd = pad(dd, 2)
var mm = d.getMonth() + 1; //Months are zero based
mm = pad(mm, 2)
var yyyy = d.getFullYear();
var date = dd + "-" + mm + "-" + yyyy;
var element = cursor.insertText(date);
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor in the document.');
}
}
function pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
函数onOpen(){
var ui=DocumentApp.getUi();
//或FormApp或电子表格应用程序。
ui.createMenu(“自定义菜单”)
.addItem('插入日期','插入日期')
.addToUi();
}
函数insertDate(){
var cursor=DocumentApp.getActiveDocument().getCursor();
如果(光标){
//尝试在光标位置插入文本。如果插入返回null,
//然后光标的包含元素不允许插入文本。
var d=新日期();
var dd=d.getDate();
dd=焊盘(dd,2)
var mm=d.getMonth()+1;//月份以零为基础
毫米=衬垫(毫米,2)
变量yyyy=d.getFullYear();
变量日期=dd+“-”+mm+“-”+yyyy;
var元素=cursor.insertText(日期);
if(元素){
元素。setBold(true);
}否则{
DocumentApp.getUi().alert('无法在此光标位置插入文本');
}
}否则{
DocumentApp.getUi().alert('在文档中找不到光标');
}
}
功能板(str,最大值){
str=str.toString();
返回str.length function insertDate() {
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
// Attempt to insert text at the cursor position. If insertion returns null,
// then the cursor's containing element doesn't allow text insertions.
var month=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
var d = new Date();
var dd = d.getDate();
dd = pad(dd, 2)
var mm = d.getMonth();
mm = pad(mm, 2)
var yyyy = d.getFullYear();
var date = dd + "-" + month[mm] + "-" + yyyy;
var element = cursor.insertText(date);
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor in the document.');
}
}
function onOpen() {
var ui = DocumentApp.getUi();
// Or FormApp or SpreadsheetApp.
ui.createMenu('Date/Time')
.addItem('Insert Date', 'insertDate')
.addToUi();
}
function insertDate() {
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
// Attempt to insert text at the cursor position. If insertion returns null,
// then the cursor's containing element doesn't allow text insertions.
// var d = new Date();
// var dd = d.getDate();
// dd = pad(dd, 2)
// var mm = d.getMonth() + 1; //Months are zero based
// mm = pad(mm, 2)
// var yyyy = d.getFullYear();
// var date = dd + "-" + mm + "-" + yyyy;
//////////////////SEE THIS ONE LINE BELOW/////////////////////////////////
var element = cursor.insertText(Utilities.formatDate(new Date(), "PST", "MMM MM-dd-yyyy hh:mm a"));
//////////////////SEE THIS ONE LINE ABOVE/////////////////////////////////
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor in the document.');
}
}
//function pad (str, max) {
// str = str.toString();
// return str.length < max ? pad("0" + str, max) : str;
//}