Reputation: 11352
If I 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!
Upvotes: 0
Views: 171
Reputation: 26488
The to_s
method provides exactly this output.
Time.zone.to_s
# => "(GMT+00:00) London"
Upvotes: 0
Reputation: 64137
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})"
Upvotes: 1