calendarApp createEvent在错误的日子添加了事件 [英] calendarApp createEvent added event on wrong day

查看:109
本文介绍了calendarApp createEvent在错误的日子添加了事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码:

 函数calEvent(){
var arrivalDate =2013年6月10日;
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);

}



当我运行它时将在正确的日历中创建活动,但它只会从6月10日至6月17日。我需要举办活动以涵盖6月10日至6月18日。

我检查过时区设置和电子表格,脚本和日历都在同一时区(Mountain Time GMT-7)



我怎样才能得到这个看似简单的代码来设置事件在正确的日期?我试过几种日期格式(utilities.formatDate),但似乎无法获得正确的格式。

预先感谢。

解决方案



我提出了上述问题几个星期前,并提出了一个工作解决方案。不知道这是否是最好的,但你可以看看,看看是否有帮助。在为我的问题开发解决方案时,我注意到了几件事情。该脚本绝对使用脚本时区来创建日期对象。但是,当它发布到日历时,它会将日期调整为执行者默认日历时区,而不是您正在编写的日历的时区。因此,如果用户的默认日历时区与正在写入的日历不同,您将获得各种疯狂​​时间。因此,上面列出的函数gasTimezoneOffset()问题是我的解决方案。



希望这有助于。


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.

解决方案

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.

这篇关于calendarApp createEvent在错误的日子添加了事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆