Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script DateTime格式化3个月_Google Apps Script_Datetime Format - Fatal编程技术网

Google apps script DateTime格式化3个月

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')

以下代码以这种格式返回日期-2014年3月21日

我们需要它以这种格式返回日期-2014年3月21日。三个字母的文本名称。当前时间很好,但不是关键时间。需要做哪些改变

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或:

函数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(Utilities.formatDate(新日期(),“PST”,“MMM-MM-dd-yyyy-hh:MM-a”); //////////////////看到上面这一行了吗///////////////////////////////// if(元素){ 元素。setBold(true); }否则{ DocumentApp.getUi().alert('无法在此光标位置插入文本'); } }否则{ DocumentApp.getUi().alert('在文档中找不到光标'); } } //功能板(str,最大值){ //str=str.toString(); //返回str.length执行脚本时,上述答案会导致以下错误。ReferenceError:“pad”未定义。如果它解决了您的请求,请将其标记为已回答。+1表示您的努力,因为OP是一个肇事逃逸询问者。(看……他们也不耐烦。)
    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;
//}