From Ruby Core documentation:
···
--------------------------------------
zone ? string
Returns the name of the time zone used for time. As of Ruby 1.8, returns “UTC” rather than “GMT” for UTC times.
t = Time.gm(2000, "jan", 1, 20, 15, 1)
t.zone #=> "UTC"
t = Time.local(2000, "jan", 1, 20, 15, 1)
t.zone #=> "CST"
--------------------------------------
strftime( string ) ? string
...
Time zone:
...
%Z - Time zone abbreviation name
C:\>ruby -v
ruby 2.0.0p353 (2013-11-22) [x64-mingw32]
C:\>irb
DL is deprecated, please use Fiddle
irb(main):001:0> Time.now
=> 2014-04-29 23:45:52 -0400
irb(main):002:0> Time.now.strftime('%Z')
=> "Eastern Daylight Time"
irb(main):003:0> Time.now.zone
=> "Eastern Daylight Time"
irb(main):004:0>
Is the documentation is wrong?
How do I get time zone abbreviation, "EDT" or "EST" instead of "Eastern Daylight Time" or "Eastern Standard Time"?
Thanks
Cannot reproduce on Debian 7 Testing (see [1]). This appears to be an
issue with Windows naming of timezones.
···
====
[1]
- ----
irb(main):005:0> Time.now.zone
=> "EDT"
irb(main):006:0> "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
=> "2.0.0p457"
- ----
On 4/29/2014 23:58, Jon A. Lambert wrote:
From Ruby Core documentation:
-------------------------------------- zone ? string Returns the
name of the time zone used for time. As of Ruby 1.8, returns “UTC”
rather than “GMT” for UTC times.
t = Time.gm(2000, "jan", 1, 20, 15, 1) t.zone #=> "UTC" t =
Time.local(2000, "jan", 1, 20, 15, 1) t.zone #=> "CST"
-------------------------------------- strftime( string ) ? string
... Time zone: ... %Z - Time zone abbreviation name
C:\>ruby -v ruby 2.0.0p353 (2013-11-22) [x64-mingw32] C:\>irb DL
is deprecated, please use Fiddle irb(main):001:0> Time.now =>
2014-04-29 23:45:52 -0400 irb(main):002:0> Time.now.strftime('%Z')
=> "Eastern Daylight Time" irb(main):003:0> Time.now.zone =>
"Eastern Daylight Time" irb(main):004:0>
Is the documentation is wrong? How do I get time zone
abbreviation, "EDT" or "EST" instead of "Eastern Daylight Time" or
"Eastern Standard Time"?
Thanks
- --
Rylee Fowler
rylee@rylee.me
https://www.rylee.me
Cannot reproduce on Debian 7 Testing (see [1]). This appears to be an
issue with Windows naming of timezones.
Agreed:
10001 % irb
Time.now.zone
=> "PDT"
Time.now.strftime "%Z"
=> "PDT"
(osx)
Maybe look at your OS's settings for your locale.
···
On Apr 29, 2014, at 21:15, Rylee Fowler <rylee@rylee.me> wrote:
I just ran this both on Mac OS X and Windows and Jon is right.
Windows:
irb(main):001:0> Time.now.zone
=> "Central Daylight Time"
Mac OS X:
2.1.0 :003 > Time.now.zone
=> "CDT”
I looked but didn’t find any setting in Windows that allowed this, but can’t help but wonder if this isn’t due to how the OS is relaying the information back.
Wayne
···
On Apr 30, 2014, at 1:42, Ryan Davis <ryand-ruby@zenspider.com> wrote:
On Apr 29, 2014, at 21:15, Rylee Fowler <rylee@rylee.me> wrote:
Cannot reproduce on Debian 7 Testing (see [1]). This appears to be an
issue with Windows naming of timezones.
Agreed:
10001 % irb
Time.now.zone
=> "PDT"
Time.now.strftime "%Z"
=> "PDT"
(osx)
Maybe look at your OS's settings for your locale.
Wayne Brissette wrote:
I looked but didn’t find any setting in Windows that allowed this, but can’t help but wonder if this isn’t
due to how the OS is relaying the information back.
I noticed if you set TZ environment variable to the below format, you get the abbreviation.
···
---------------------------------
C:\>set TZ=EST-5EDT
C:\>irb
irb(main):001:0> Time.now.zone
=> "EDT"
irb(main):002:0>
------------------------------
The TZ environment variable is not set on Windows by default.
If TZ is not set it's apparently retrieved from registry under the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
Curiously Cygwin's default bash/cshell exports 'TZ = America/New_York', using a program (tzset),
and Cygwin's ruby does show 'Time.now.zone' => 'EDT'.
I assume there's a zone lookup table in Cygwin that its NEWLIB is using,
but not in MSys (rather... MSys is probably using MSVCRTL.DLL).
I'm guessing the only way to make it work exactly the same on all platforms is to include
a platform independent strftime() (or whatever is used) in ruby core with its own zone
abbreviation table.
Jon