Ruby converting UTC to user's time zone

前端 未结 3 1624
遇见更好的自我
遇见更好的自我 2021-01-06 10:15

I have dstring as saved in UTC. While I have user\'s timezone\'s offset standard_offset What I want to show that date in user\'s timezone after con

3条回答
  •  没有蜡笔的小新
    2021-01-06 11:03

    Apparently this is an issue with the Ruby standard library.

    Sources:

    http://rubydoc.info/gems/tzinfo/file/README.md

    Note that the local Time returned will have a UTC timezone (local.zone will return "UTC"). This is because the Ruby Time class only supports two timezones: UTC and the current system local timezone.

    http://librelist.com/browser//usp.ruby/2011/9/24/unix-time-and-the-ruby-time-class/

    Modern kernels do not know nor care about timezones. Conversions from UTC to the local timezone (and vice versa) are done in user space[2]. Different processes running concurrently on the same machine do not necessarily share the same local timezone.

    Process timezone

    The "TZ" environment variable controls the timezone for a given process, and thus the timezone attached to a Ruby Time object. If "TZ" is unset, the timezone of the process is implementation-defined.

    As far as I can tell, everything related to time zones that is in Rails was built by the Rails core team. Ruby only handles as much time-related functionality as Unix provides and probably expects the user to handle the reset.

提交回复
热议问题