This question already has answers here:
DateTime formatting 3 letter month
(2个答案)
4年前关闭。
以下代码导致:21-undefined-2014不知道缺少什么。请检查并告知。其他一切似乎都正常工作。谢谢。
查看此内容以确认http://jsfiddle.net/baljeetsingh/JMs7t/2/
(2个答案)
4年前关闭。
以下代码导致:21-undefined-2014不知道缺少什么。请检查并告知。其他一切似乎都正常工作。谢谢。
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 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 pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
最佳答案
你不应该那样做
mm = pad(mm, 2)
查看此内容以确认http://jsfiddle.net/baljeetsingh/JMs7t/2/
关于javascript - DateTime错误21-undefined-2014 ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22572712/
10-13 03:16