本文介绍了为什么Google Calendar API会返回timeZone = UTC,虽然它不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的大部分客户都是美国人,但是在将他们的Google日历连接到我们的服务后,我们读取了timeZone = UTC:
https ://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole = owner& access_token =< ACCSES TOKEN>
回应:
{
pre>
kind:calendar#calendarList,
etag:\1407366566837000\,
nextSyncToken:00001407366566837000,
items:[
{
kind:calendar#calendarListEntry,
etag:\1407184723757000\,
id:sampleemail@gmail.com,
summary:sampleemail@gmail.com,
timeZone:UTC,
colorId:17 ,
backgroundColor:#9a9cff,
foregroundColor:#000000,
selected:true,
accessRole:owner,
defaultReminders:[
{
method:popup,
minutes:30
}
],
notificationSettings:{
notifications:[
{
type:eventCreation,
method:email
},
{
type:eventChange,
method:email
},
{
类型:eventCancellation,
method:email
},
{
type:eventResponse,
method:电子邮件
]
},
主:真
}
]
}
碰巧有很多用户,我们很确定他们的日历实际上是未设置为UTC,但Google始终返回UTC。
熟悉这个问题的人吗?解决方案
我的后端ruby代码:
time_zone ='Europe / Moscow'
task_time_start_utc = task.date_time
task_time_start_moscow = task_time_start_utc.in_time_zone(time_zone)
task_time_end_utc = task_time_start_utc + task.duration.minutes
task_time_end_moscow = task_time_end_utc.in_time_zone(time_zone)
event_property = {
summary:task.name,
位置:#{task.lat}#{task.lng},
描述:string_work_times,
start:{
date_time:task_time_start_moscow.to_formatted_s(:iso8601),
time_zone:time_zone
},
结束:{
date_time:task_time_end_mosc ow.to_formatted_s(:iso8601),
time_zone:time_zone
}
}
Most of our customers are American, but after connecting their google calendar with our service we read timeZone=UTC:
https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=owner&access_token=<ACCSES TOKEN>
response:
{ "kind": "calendar#calendarList", "etag": "\"1407366566837000\"", "nextSyncToken": "00001407366566837000", "items": [ { "kind": "calendar#calendarListEntry", "etag": "\"1407184723757000\"", "id": "sampleemail@gmail.com", "summary": "sampleemail@gmail.com", "timeZone": "UTC", "colorId": "17", "backgroundColor": "#9a9cff", "foregroundColor": "#000000", "selected": true, "accessRole": "owner", "defaultReminders": [ { "method": "popup", "minutes": 30 } ], "notificationSettings": { "notifications": [ { "type": "eventCreation", "method": "email" }, { "type": "eventChange", "method": "email" }, { "type": "eventCancellation", "method": "email" }, { "type": "eventResponse", "method": "email" } ] }, "primary": true } ]
}
it happens to a lot of users, and we're pretty sure their calendar is actually not set to UTC, but Google consistently returns UTC.Anyone familiar with this problem?
解决方案https://support.google.com/calendar/answer/2367918?hl=en
My backend ruby code:
time_zone = 'Europe/Moscow' task_time_start_utc = task.date_time task_time_start_moscow = task_time_start_utc.in_time_zone(time_zone) task_time_end_utc = task_time_start_utc + task.duration.minutes task_time_end_moscow = task_time_end_utc.in_time_zone(time_zone) event_property = { summary: task.name, location: "#{task.lat} #{task.lng}", description: string_work_times, start: { date_time: task_time_start_moscow.to_formatted_s(:iso8601), time_zone: time_zone }, end: { date_time: task_time_end_moscow.to_formatted_s(:iso8601), time_zone: time_zone } }
这篇关于为什么Google Calendar API会返回timeZone = UTC,虽然它不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!