问题
I want to display the Timezone abbreviation. But my Ruby keeps giving me the fullform.
irb(main):001:0> Time.now
=> 2014-02-28 15:11:21 +0530
irb(main):002:0> Time.now.zone
=> "India Standard Time"
irb(main):003:0>
This was in Ruby 1.9.3p125. Tried in Ruby 2.0 as well and same results! Even strftime("%Z")
gives full form of the time zone and not the abbreviation.
But the documentation clearly states that only the abbreviation should be returned. I am actually building a rhodes
application on Windows 7
EDIT: Time.now.strftime("%Z")
also gives full form.
Is this coz of Windows?
回答1:
This issue does seem to be Windows specific as I was able to reproduce it myself.
Even in the documentation, it states: Also, %Z is highly dependent on the operating system. For example, it may generate a non ASCII string on Japanese Windows. i.e. the result can be different to “JST”.
I looked around and I couldn't seem to find any simple solution to this as it is so dependent on the operating system.
来源:https://stackoverflow.com/questions/22092281/ruby-time-zone-returns-full-form-in-windows-7