Google日历API ruby ,日期时间

问题描述 投票:1回答:1

我有这个代码。这会在我的谷歌日历中创建一个事件。

    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)

我究竟做错了什么?

ruby google-calendar-api
1个回答
1
投票

你在17:50:00输入UTC+0的时间(来自你的+00:00date_time代表UTCUTC+0),然而,你指定了一个time_zone,你使用的是跟随时区UTC-6的Monterrey。

我的猜测是,你的代码在17:50:00中使用UTC+0然后将其转换为蒙特雷时区UTC-6,结果为11:50:00。要么尝试删除+00:00或尝试制作-06:00

© www.soinside.com 2019 - 2024. All rights reserved.