Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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
Javascript 谷歌应用程序脚本日期分为两列_Javascript_Date_Google Apps Script - Fatal编程技术网

Javascript 谷歌应用程序脚本日期分为两列

Javascript 谷歌应用程序脚本日期分为两列,javascript,date,google-apps-script,Javascript,Date,Google Apps Script,我想连接两个单元格,在应用程序脚本中创建一个日期,以便将事件添加到日历中 function AgendaL13 () { var classeur = SpreadsheetApp.getActive(); var feuille1 = classeur.getSheetByName("TABLEAU DE BORD") var sheetNom = feuille1.getRange("D4").getDisplayValue(); //Nom client var tit

我想连接两个单元格,在应用程序脚本中创建一个日期,以便将事件添加到日历中

 function AgendaL13 () {
  var classeur = SpreadsheetApp.getActive();
  var feuille1 = classeur.getSheetByName("TABLEAU DE BORD") 
  var sheetNom = feuille1.getRange("D4").getDisplayValue(); //Nom client
  var titre = feuille1.getRange("E5").getDisplayValue(); // title of event
  var cal = CalendarApp.getDefaultCalendar(); // default calendar

  var date = feuille1.getRange('H13').getValue(); // date 22/12/2016
  var heure = feuille1.getRange('I13').getValue(); // Hour 18:00

  var dateNew = date+heure;

  cal.createEvent(sheetNom+ " : " +titre, dateNew, dateNew);
}
我想要datenew=2016年12月22日星期四18:00:00 GMT+0100(CET)

可能吗? 对不起,我英语不好(我是法国人)

试试:

date.setHours(heure.getHours());
date.setMinutes(heure.getMinutes()); // if you use minutes
date.setSeconds(heure.getSeconds()); // if you use seconds

这将把
date
的时间设置为
heure
的时间。

我也在处理类似的案例。这对我很有用:

function myFunction()
{
  var sheet = SpreadSheetApp.openById("SheetId").getSheetByName("SheetName");
  var data = sheet.getDataRange(2,1,sheet.getLastRow(),sheet.getLastColumn()).getValues();

  var date = data[rowIndexforDate][columnIndexforDate];
  var time = data[rowIndexforTime][columnIndexforTime];

  var eventTime = setTimeToDate(date,time);

  //after this would be the code for the creation of the event
}

function setTimeToDate(date,time) //this function does the job
{
  var t = time.split(":"); //in my case the time is separated by ":"

  var dateMod = new Date(date.setHours(t[0],t[1],t[2],0));
  return dateMod;
}