If I 开发者_StackOverflow社区know the Time.zone e.g. London, any ideas on how I can display
(GMT+00:00) London
without assigning
Time.zone = "London"
and then calling
puts Time.zone
Thanks in advance!
You can call:
Time.zone.formatted_offset
Which will:
returns the offset of this time zone as a formatted string, of the format “+HH:MM”.
per: http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html#method-i-formatted_offset
So if you wanted to format the string, you could do:
"GMT(#{Time.zone.formatted_offset})"
The to_s
method provides exactly this output.
Time.zone.to_s
# => "(GMT+00:00) London"
精彩评论