[英]setHours() Error when Creating a Google Calendar Event from Imported Date Coming From Spreadsheet - Apps Script
I have a form that requests an event title and start time from a user. 我有一个表单,要求用户提供事件标题和开始时间。 Then inserts the information into a Google Spreadsheet.
然后将信息插入Google电子表格中。 I wrote a script that imports this information into Google Calendar.
我写了一个脚本,将这些信息导入Google日历。 However, I want every entered event to have an end time 2 hours later than the start time.
但是,我希望每个输入的事件的结束时间比开始时间晚2小时。 Is there an easy way to do this?
是否有捷径可寻? Here is what I have so far.
这是我到目前为止所拥有的。
var title = column[3];
var startDate = column[5]; // 5th column in spreadsheet "Start Date and Time"
cal1.createEvent(title, new Date(startDate), new Date(startDate.setHours(startDate.getHours() + 2));
I am getting the error: 我收到错误:
TypeError: Cannot find function sethours in object Fri Feb 27 2015 08:00:00 GMT-0500 (EST
The value being returned from your spreadsheet for startDate
is not being coerced into a date type. 从电子表格中为
startDate
返回的值不会被强制转换为日期类型。 You'll need to use new Date()
on it to make it a date: 你需要在它上面使用
new Date()
来使它成为一个日期:
var startDate = column[5]; // 5th column in spreadsheet "Start Date and Time"
startDate = new Date(startDate);
Here is a test function that I ran, with some changes to the code: 这是我运行的测试函数,对代码进行了一些更改:
function testIt() {
var title = column[3];
var startDate = column[5]; // 5th column in spreadsheet "Start Date and Time"
startDate = new Date(startDate);
var startHr = startDate.getHours();
var eventEndTime = new Date(startDate);
eventEndTime.setHours(startHr + 2);
cal1.createEvent(title, startDate, eventEndTime);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.