在Google脚本中延长日历活动持续时间

时间:2015-01-22 21:13:16

标签: google-apps-script google-calendar-api

我正在尝试使用google脚本在我的日历中获取当前现有事件,如果脚本成功获取当前事件,我想在几分钟内扩展它,在这种情况下假设为10。我已经发现了这个:How to add minutes to my Date但似乎无法使用谷歌脚本。

有人可以帮我这个吗?

此致

1 个答案:

答案 0 :(得分:1)

您添加“How to add minutes to my Date”的链接是Java中的谷歌脚本或Javascript。 Java和javascript是两种不同的编程语言。

This应该向您展示如何从日历中获取现有的日历活动。它会搜索日历中包含关键字的事件,但会将信息导出到有效的电子表格中 - 这不是您想要的。

以下是Google Apps脚本中的关键代码:

// Reference Websites:
// https://developers.google.com/apps-script/reference/calendar/calendar
// https://developers.google.com/apps-script/reference/calendar/calendar-event
//

var mycal = "user@gmail.com"; // change this email to yours
var cal = CalendarApp.getCalendarById(mycal);

// Optional variations on getEvents
// var events = cal.getEvents(new Date("January 3, 2014 00:00:00 CST"), new Date("January 14, 2014 23:59:59 CST"));
// var events = cal.getEvents(new Date("January 3, 2014 00:00:00 CST"), new Date("January 14, 2014 23:59:59 CST"), {search: 'word1'});
// 
// Explanation of how the search section works (as it is NOT quite like most things Google) as part of the getEvents function:
//    {search: 'word1'}              Search for events with word1
//    {search: '-word1'}             Search for events without word1
//    {search: 'word1 word2'}        Search for events with word2 ONLY
//    {search: 'word1-word2'}        Search for events with ????
//    {search: 'word1 -word2'}       Search for events without word2
//    {search: 'word1+word2'}        Search for events with word1 AND word2
//    {search: 'word1+-word2'}       Search for events with word1 AND without word2
//
var events = cal.getEvents(new Date("January 12, 2014 00:00:00 CST"), new Date("January 18, 2014 23:59:59 CST"), {search: 'event name'});

要将事件的结束时间延长10分钟,您可以使用getStartTime, getEndTime and setTime。您可以像我在下面一样使用日期字段。

喜欢:

var newEndTime = new Date(events[eventNumber].getEndTime()+10);
var startTime = new Date(events[eventNumber].getStartTime());
events[eventNumber].setTime(startTime,newEndTime);