我试图通过日历API将库存月相日历添加到网站。但是......数据总是以UTC格式返回。例如,这个获取请求
https://www.googleapis.com/calendar/v3/calendars/ht3jlfaac5lfd6263ulfh4tql8%40group.calendar.google.com/events?orderBy=startTime&singleEvents=true&timeMin=2017-10-31T00%3A00%3A00-05%3A00&timeMax=2018-01-07T00%3A00%3A00-05%3A00&maxResults=10&timeZone=America%2FNew_York&key={API_KEY}
给我这个回复
{
"kind": "calendar#events",
"etag": "\"p32o9hktouumte0g\"",
"summary": "Phases of the Moon",
"updated": "2017-11-07T18:33:19.000Z",
"timeZone": "UTC",
"accessRole": "reader",
"defaultReminders": [],
"nextPageToken": "EiIKF21vb25waGFzZSsxNTA5NzcyOTgwMDAwGICAm7jOo9cC",
"items": [
{
"kind": "calendar#event",
"etag": "\"2453932800000000\"",
"id": "moonphase+1509772980000",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=bW9vbnBoYXNlKzE1MDk3NzI5ODAwMDAgaHQzamxmYWFjNWxmZDYyNjN1bGZoNHRxbDhAZw&ctz=America/New_York",
"created": "2008-11-18T00:00:00.000Z",
"updated": "2008-11-18T00:00:00.000Z",
"summary": "Full moon 5:23am",
"creator": {
"email": "ht3jlfaac5lfd6263ulfh4tql8@group.calendar.google.com",
"displayName": "Phases of the Moon",
"self": true
},
"organizer": {
"email": "ht3jlfaac5lfd6263ulfh4tql8@group.calendar.google.com",
"displayName": "Phases of the Moon",
"self": true
},
"start": {
"date": "2017-11-04"
},
"end": {
"date": "2017-11-05"
},
"visibility": "public",
"iCalUID": "moonphase+1509772980000@google.com",
"sequence": 0,
"gadget": {
"title": "Full moon 5:23am",
"iconLink": "https://ssl.gstatic.com/calendar/images/moon/full-moon.gif"
}
}
]
}
您会注意到timeZone被列为UTC,摘要和说明字段包含UTC时间的文本表示。它似乎有点认可我的时区,因为htmlLink字段将该区域显示为America / New_York。
你可能会认为这只是它的工作方式,除了......
如果您在
上访问此API的Google测试页https://developers.google.com/google-apps/calendar/v3/reference/events/list
然后插入这些参数,日历数据会回到America / New_York区域。
关于实现这一目标的魔力的任何想法?