【发布时间】:2017-06-20 14:29:22
【问题描述】:
我正在尝试将以下日期和时间组合转换为 UTC
from_date: "2017-06-19",from_time: "14:00"
to_date: "2017-06-19", to_time: "23:00"
Timezone: EDT
我正在使用下面的代码进行转换
Date.parse(dt).to_datetime + Time.parse(t).utc.seconds_since_midnight.seconds
它为 to_date 和 to_time 组合提供了错误的日期值。
输出:
Date.parse(from_date).to_datetime +
Time.parse(from_time).utc.seconds_since_midnight.seconds
#⇒ **Mon, 19 Jun 2017 18:00:00 +0000**
Date.parse(to_date).to_datetime +
Time.parse(to_time).utc.seconds_since_midnight.seconds
#⇒ **Mon, 19 Jun 2017 03:00:00 +0000**
以上转换应改为“Tue, 20 Jun 2017 03:00:00 +0000”。
【问题讨论】:
标签: ruby ruby-on-rails-3 date datetime