【问题标题】:How do I find out the time zone name from ISO 8601 string in Rails?如何从 Rails 中的 ISO 8601 字符串中找出时区名称?
【发布时间】: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


【解决方案1】:

这是不可能的。没有从偏移量到时区的映射(尽管在一年中的固定时间存在从时区到偏移量的映射)。许多时区可能共享一个偏移量。

【讨论】:

    猜你喜欢
    • 2023-02-21
    • 1970-01-01
    • 2018-02-13
    • 2011-02-04
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多