ruby - 谷歌日历 API 红宝石,日期时间时区
问题描述
我有这个代码。它在我的谷歌日历中创建了一个事件。
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 小时。
如果我去谷歌日历我的活动是第 15 天 (11 - 11:50),而不是 (17 - 17:50)
我究竟做错了什么?
解决方案
您正在输入时间17:50:00
(UTC+0
从+00:00
您的date_time
代表UTC
或UTC+0
),但是,您指定了time_zone
您使用蒙特雷的地方,它遵循时区UTC-6
。
我的猜测是,您的代码17:50:00
输入UTC+0
然后将其转换为蒙特雷时区UTC-6
,结果为11:50:00
. 尝试删除+00:00
或尝试制作它-06:00
。
推荐阅读
- haskell - MonadBaseControl 法律
- memory-leaks - 防止 react-konva 中的内存泄漏
- r - 按 R 中时间序列数据的 10 分钟间隔分组并求和
- python - 无法将 Py 文件作为批处理 .BAT 文件运行
- flutter - 如何在颤振中使用 NFC 在两部手机之间发送数据?
- javascript - 无法使用授权代码流向 Web Playback API 进行身份验证
- ruby-on-rails - 如何让路由助手使用现有参数?
- react-native - npm start 命令在本机反应中给出错误
- google-apps-script - 谷歌应用脚本没有遍历所有文件
- java - 如何在自定义对象中循环遍历 ArrayList?