How to Convert TZInfo identifier to Rails TimeZone name/key

后端 未结 2 1803
你的背包
你的背包 2020-12-24 12:08

How do you convert js values received as TZInfo identifiers to Rails TimeZone name/key?

FROM: \"America/New_York\" returned fro

2条回答
  •  自闭症患者
    2020-12-24 13:07

    Temporal includes the needed logic, but to answer your question:

    Time.zone = ActiveSupport::TimeZone.new("America/New_York")

    Edit, I guess my answer is incomplete. You want to get it from "America/New_York" to "Eastern Time (US & Canada)", correct? If that's the case this is the best solution I have -- though someone may be able to provide a better one.

    ActiveSupport::TimeZone::MAPPING.select {|k, v| v == "America/New_York" }.keys.first

提交回复
热议问题