tags:

views:

19

answers:

1

$ irb

ruby-1.9.2-p0 > RUBY_DESCRIPTION
 => "ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]" 

ruby-1.9.2-p0 > Time.now
 => 2010-09-07 18:18:38 -0700 

ruby-1.9.2-p0 > Time.now.gmtime
 => 2010-09-08 01:18:43 UTC 

ruby-1.9.2-p0 > Time.now.strftime('%H:%M %Z')
 => "18:22 PDT"

ruby-1.9.2-p0 > Time.now.gmtime.strftime('%H:%M %Z')
 => "01:22 UTC" 

But I don't see any method to show the time in East Coast or Central / Mountain time, or to change the zone to something other than GMT? There seems to have no way to tell strftime() to use a particular time zone when displaying the time.

+1  A: 

Check out the tzinfo gem.

AboutRuby
looks like ActiveSupport has it too: http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html
動靜能量
but the thing is, if it is possible to know how to convert local time to GMT, then it should be possible to convert the GMT back to local time too. And that means, if "local" is a different time zone, it should know how to convert GMT to that "local" time as well. Maybe Ruby just is slim right now that it won't do it... but... if I have to say, "Ruby is a really powerful language", and then someone asks me, ok, let's ask it to print the East Coast time or West Coast time, and I have to answer, "by itself, it can't easily do it".
動靜能量
Let's get this straight, you are judging _language_ by its ability to deal with _timezones_?
Mladen Jablanović
We live in the real world, and there are distances, where there are 3 dimension, and there is time, which is the other dimension. so if Ruby can do addition, convert kilometer to miles, but it cannot convert West Coast time to East Coast time, then it is somewhat lacking.
動靜能量