我有这个代码。这会在我的谷歌日历中创建一个事件。
client = Signet::OAuth2::Client.new(client_options)
client.update!(session[:authorization])
service = Google::Apis::CalendarV3::CalendarService.new
service.authorization = client
event = Google::Apis::CalendarV3::Event.new({
start: Google::Apis::CalendarV3::EventDateTime.new(
date_time: cf_event.starts_at.to_datetime.rfc3339,
time_zone: 'America/Monterrey'
),
end: Google::Apis::CalendarV3::EventDateTime.new(
date_time: cf_event.ends_at.to_datetime.rfc3339,
time_zone: 'America/Monterrey'
),
summary: cf_event.title
})
这是一个基本的例子,我的cf_event
对象有starts_at
attr,这是一个timeWithZone。
所以我不得不做cf_event.starts_at.to_datetime.rfc3339
。
输出“2019-03-15T17:50:00 + 00:00”
问题是,代码创建,事件但是-6小时。
如果我去谷歌日历我的活动是在(11 - 11:50)的第15天,而不是(17 - 17:50)
我究竟做错了什么?
你在17:50:00
输入UTC+0
的时间(来自你的+00:00
的date_time
代表UTC
或UTC+0
),然而,你指定了一个time_zone
,你使用的是跟随时区UTC-6
的Monterrey。
我的猜测是,你的代码在17:50:00
中使用UTC+0
然后将其转换为蒙特雷时区UTC-6
,结果为11:50:00
。要么尝试删除+00:00
或尝试制作-06:00
。