【发布时间】:2014-10-12 17:13:17
【问题描述】:
我有时间使用 ISO 8601 格式。
2014-08-19T23:26:23+09:00
如何从时间字符串中找出时区名称。
我在下面试过了。
Time.zone.parse('2014-08-19T23:26:23+09:00')
# This returns the time in the time zone I have set(UTC by default)
Time.parse('2014-08-19T23:26:23+09:00')
# This returns the time in the system time zone
如果我知道我可以做的时区名称
Time.parse('2014-08-19T23:26:23+09:00').in_time_zone('Asia/Tokyo').zone.name
=> 'JST'
很遗憾,我没有时区名称。有什么想法吗?
【问题讨论】:
-
时间字符串可以指任何 UTC 偏移量为 +09:00 的时区,而不仅仅是亚洲/东京
-
在the timezone tag wiki中读取“时区!=偏移量”
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 timezone