创建查询参数以设置开始和结束日期/时间

时间:2018-06-08 17:01:25

标签: javascript date url parameters

我一直在尝试创建查询参数,以设置从标记/链接添加到Google日历的开始日期/时间和结束日期/时间。

我的查询参数如下:

`https://calendar.google.com/calendar/r/eventedit?text=${Title}&dates=${event.Year}${
  Months.findIndex(e => e === Month) < 10
  ? `0${Months.findIndex(e => e === Month)}`
  : Months.findIndex(e => e === Month)
}${event.Day}${StartTime}T120000Z/${EndYear}${
  Months.findIndex(e => e === EndMonth) < 10 
  ? `0${Months.findIndex(e => e === EndMonth)}`
  : Months.findIndex(e => e === EndMonth)
}${EndDay}${EndTime}T130000Z&sf=true&output=xml`

如果我删除了开始/结束时间变量,那么它将成功加载页面并显示正确的StartDate但EndDate将不会显示。说实话,我不理解T130000Z但没有它就行不通。

它重定向到的链接(部分有效)在下面:

https://calendar.google.com/calendar/r/eventedit?text=Class%20of%202018%20graduation%20celebration&dates=20181212T120000Z/20180426T130000Z&sf=true&output=xml

根据@ StephenP的评论,我更新了查询以包含时间。

我将T120000Z更改为T $ {StartTime.split(':')。join('')} 00Z成功将T010100Z添加到网址中。

然而,尽管如此,日历页面不会更新除标题之外的任何字段。只是默认为今天的日期。

1 个答案:

答案 0 :(得分:1)

这是我尝试的组合,并且能够设置日期:

我所做的改变是(在查询中):
sf = true =&gt; sf = false
dates = <YYYYMMDD>/<YYYYMMDD>(START_DATE / END_DATE + 1)

示例:
https://calendar.google.com/calendar/r/eventedit?text=Class%20of%202018%20graduation%20celebration&dates= 20180611 / 20180615&安培; sf=false&安培;输出= XML

<强>输出 Example Output