Google 工作表脚本中的日历事件提前一天结束

Google Calendar event from sheets script ends a day early

我有一个工作表文件,可以在单击按钮时创建一个日历事件。日历事件基于用户输入的截止日期、脚本创建的开始日期、输入的位置和输入的描述,这些都是从电子表格中的某些单元格中提取的。问题是,当我转到日历时,事件在截止日期前一天(或截止日期当天的开始)结束,我希望它显示整个截止日期。例如,如果我在电子表格中输入 7 月 17 日的截止日期,当我创建日历事件时,它只会运行到 16 日。有没有一种方法可以让事件安排到一天结束,或者有一种简单的方法可以在脚本中将结束日期偏移一天。

  var Description = sheetTemplate.getRange('B12').getValue(); //gets discription from Cell B12
  var Location = sheetTemplate.getRange('C5') .getValue();  //gets location of work order from cell C5
  var StartDate = sheetTemplate.getRange('C4').getValue();  //Start Date from Cell C4
  var DueDate = sheetTemplate.getRange('E5').getValue();    //Gets Due Date From Cell E5


     //This portion of the code schedules the WO on the calendar//

var eventCal = CalendarApp.getCalendarById("XXXXX") ;//Get the Maintenance Calendar
var options = { 'location': Location, 
             'description':Description
            } //sets event details

var WOevent = eventCal.createAllDayEvent(WOname,StartDate,DueDate,options);//creates a calendar event

WOevent.setColor('10') // sets the color of the calendar event to green

你有两个选择

  • 或者您手动将一天添加到截止日期

这可以用new Date(ms)来完成:

var DueDate = sheetTemplate.getRange('E5').getValue(); 
DueDate = new Date(DueDate.getTime() + 24*60*60*1000);

这允许您在 DueDate 上指定结束时间:

var DueDate = sheetTemplate.getRange('E5').getValue();
DueDate = new Date(DueDate);
DueDate.setHours(23);
DueDate.setMinutes(59);
var WOevent = eventCal.createEvent(WOname,StartDate,DueDate,options);