Ruby 如何利用夏令时将UTC转换为EST

Ruby 如何利用夏令时将UTC转换为EST,ruby,Ruby,我正在使用API调用从网站获取以下输出: out_string += "Incident Created :" + nextOncall_result['incident']['created_at'].to_s + "\n" “created_at”给出了事件发生的时间。该网站是UTC的,我想通过使用夏令时将其转换为EST 请帮帮我。如果可能,请更改代码。在rails中,您可以执行以下操作: nextOncall_result['incident']['created_at'].in_tim

我正在使用API调用从网站获取以下输出:

out_string += "Incident Created :" + nextOncall_result['incident']['created_at'].to_s + "\n"
“created_at”
给出了事件发生的时间。该网站是UTC的,我想通过使用夏令时将其转换为EST

请帮帮我。如果可能,请更改代码。

在rails中,您可以执行以下操作:

nextOncall_result['incident']['created_at'].in_time_zone('EST')
UPD

require 'tzinfo'
offset = TZInfo::Timezone.get('EST').current_period.offset.utc_total_offset
time_with_dst_in_utc = nextOncall_result['incident']['created_at'] + offset
res = time_with_dst_in_utc.strftime('%d/%m/%Y %m:%S')

这是我正在创建的输出:2018-04-14T19:25:04Z,您可以看到它是UTC格式的,我希望它是EST格式的。请帮助您的预期结果是什么?我希望创建事件这样的预期结果:2018-04-14T03:25:04Zin EST时区每当网站中出现任何事件时,它都将显示在EST中,因为我的配置文件时区是EST,网站是UTC,我使用API调用获取输出,但以上输出以UTC格式提供,请帮助@stephanI我没有使用ruby on rails请建议使用RubyRequeste'date'DateTime.parse(nextOncall_result['incident']['created_at'].to_s)。新的_偏移量('EST')。to_sHi andriy baran,谢谢你的代码。你能帮我把代码和夏令时一起修改吗?请帮我修改一下。请看文档