Get today date in google appScript

后端 未结 5 1285
旧时难觅i
旧时难觅i 2021-02-01 15:48

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 = Spreadsheet         


        
5条回答
  •  [愿得一人]
    2021-02-01 16:13

    The following can be used to get the date:

    function date_date() {
    var date = new Date();
    var year = date.getYear();
    var month = date.getMonth() + 1;  if(month.toString().length==1){var month = 
    '0'+month;}
    var day = date.getDate(); if(day.toString().length==1){var day = '0'+day;}
    var hour = date.getHours(); if(hour.toString().length==1){var hour = '0'+hour;}
    var minu = date.getMinutes(); if(minu.toString().length==1){var minu = '0'+minu;}
    var seco = date.getSeconds(); if(seco.toString().length==1){var seco = '0'+seco;}
    var date = year+'·'+month+'·'+day+'·'+hour+'·'+minu+'·'+seco;
    Logger.log(date);
    }
    

提交回复
热议问题