From: "Ara.T.Howard" Date: 2004-08-04T23:11:30+09:00 Subject: Re: Time#zone On Wed, 4 Aug 2004, Farrel Lifson wrote: > I'm running Ruby 1.8 on XP (ruby 1.8.1 (2003-12-25) [i386-mswin32]). > Currently Time#zone returns a long form of the timezone for me : > irb(main):001:0> Time.now.zone > => "South Africa Standard Time" > > On Linux (ruby 1.8.1 (2004-05-02) [i686-linux-gnu]) I get the > shortened time zone code which is what I would like to get on XP: > irb(main):001:0> Time.now.zone > => "SAST" > > I've looked through Time#methods and I can't see a way to get the > shortened code on XP without doing some processing on the result > (probably just get the first letter of every word) which is not > something I'd like to do as the script will be run on both Linux and > XP and I'd like to have it as clean as possible with no OS specific > exceptions. > > Thanks, > Farrel i don't have a windows box handy, but this should work ~ > ruby -e 'print(Time.now.strftime("%z\n"))' -0600 eg. use rfc numeric time zone offest codes instead of the abbreviated ones. you could also try this ~ > ruby -e 'print(Time.now.strftime("%Z\n"))' MDT and play with with the env vars TZ and LC_TIME (man strftime). but i doubt you'll get a uniform alpha time zone desc as my man page says %Z The time zone or name or abbreviation. eg. abbreviations may not not seem to be specified by the spec. using ENV['LC_TIME'] = 'C' p Time.now.zone or ENV['LC_TIME'] = 'POSIX' p Time.now.zone __may__ affect output. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================