我在后端定义了一个模型,定义为
class TimezoneIdentifier < Sequel::Model
end
在我的前端反应组件中,我需要以 UTC-5 Ontario 等格式显示时区。有没有办法做到这一点?
我的数据库包含来自 TZInfo gem 的所有时区标识符。
我没有使用 Rails。
您需要实现类似于ActiveSupport::TimeZone
's 的功能。在这里查看https://github.com/rails/rails/blob/master/activesupport/lib/active_support/values/time_zone.rb#L306#to_s
_#formatted_offset
#utc_offset
或者您可以ActiveSupport::TimeZone
在没有其余部分的情况下ActiveSupport
使用 with require 'active_support/values/time_zone'
。