calendarApp createEvent added event on wrong day

这一生的挚爱 提交于 2019-12-13 05:56:12

问题


Here is my code:

function calEvent(){
   var arrivalDate = "06/10/2013";
   var departureDate = "06/18/2013";
   var start = new Date(arrivalDate);
   var end = new Date(departureDate);

   var cal = CalendarApp.getCalendarById('id487g3esn088a00omqa99ugv0@group.calendar.google.com');
   cal.createEvent('Apollo 11 Landing',start,end);

}

When I run this it will create the event in the correct calendar however it will only be from June 10 thru June 17. I need the event to cover June 10 - June 18.

I have checked the Timezone setting and the spreadsheet, script and calendar are all on the same time zone (Mountain Time GMT-7)

How can I get this seemingly simple code to set the event on the correct dates? I've tried several date formatting (utilities.formatDate) but can't seem to get the correct format.

Thanks in advance.


回答1:


How to use timeZone of calendar to set timeZone for date object

I posed the above question a couple a weeks ago, and came up with a working solution. Not sure if it is the best or not, but you can look over and see if it helps. In working on a solution for my question I noticed several things. The script definitely uses the script timezone to create a date object. But when it post to a calendar it adjust the date to executors default calendar timezone not the timezone of the calendar you're writing too. So if a user's default calendar timezone is different from the calendar being written to you will get all kind of crazy time's

So the function gasTimezoneOffset() that is listed in the above question was my solution for this.

Hope this helps.



来源:https://stackoverflow.com/questions/16410846/calendarapp-createevent-added-event-on-wrong-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!