将UTC时间换算为太平洋时间 [英] Converting Time in UTC to Pacific time

查看:497
本文介绍了将UTC时间换算为太平洋时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从外部方法获得一个带有时间和日期的字符串,例如 10/07/07 14:50 有什么方法可以转换该时间在美国太平洋时间知道红宝石的 UTC时间?日期中发生的更改?也就是说,如果时间差导致一天中的日期不同。

I get a string from a external method with a time and date like so "07/09/10 14:50" is there any way I can convert that time in ruby to 'Pacific US' time knowing its 'UTC' time? with changes accounted for in the date? I.e if the time difference results in the day being different.

推荐答案

由于您似乎正在使用滑轨,因此您有很多选项。我建议阅读这篇文章,其中讨论了所有时区。

Since it appears you are using rails, you have quite a few options. I suggest reading this article that talks all about time zones.

要转换为PST,这两种方法都是特定于rails的方法。无需重新发明轮子:

To convert to PST, both of these are rails-specific methods. No need to re-invent the wheel:

time = Time.parse("07/09/10 14:50")
time.in_time_zone("Pacific Time (US & Canada)")

希望如此帮助

更新:rails可能会尝试变得更聪明,并为您指定的字符串时间指定时区。为了确保时间解析为UTC,您应该在字符串中指定:

UPDATE: rails might try to get smart and give the time you specify as a string a time zone. To ensure that the time parses as UTC, you should specify in the string:

time = Time.parse("07/09/10 14:50 UTC")
time.in_time_zone("Pacific Time (US & Canada)")

这篇关于将UTC时间换算为太平洋时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆