Hi - I cant seem to get localtime to work, can anyone share some gotchas? ## check environment is setup [dc@fox:~]$ echo $TZ Japan/Tokyo [dc@fox:~]$ irb irb(main):001:0> ENV['TZ'] => "Japan/Tokyo" # so the env is coming through ok... or is it? irb(main):021:0> u=Time.now.utc => Tue Jan 04 06:21:25 UTC 2011 irb(main):019:0> t1=Time.now.localtime => Tue Jan 04 06:21:02 +0000 2011 irb(main):020:0> t1.zone => "UTC" ### so it seems zone is being ignored # is there any way to override/forcibly set the timezone? irb(main):006:0> t1.localtime => Tue Jan 04 06:12:56 +0000 2011 # doesnt change, i guess cos zone is locked irb(main):009:0> t1.localtime("+09:00") ArgumentError: wrong number of arguments (1 for 0) from (irb):9:in `localtime' from (irb):9 from :0 ## according to docs this should work: http://www.ruby-doc.org/core/classes/Time.html#M000346 ### ok, trying to set the timezones irb(main):001:0> Time.new.zone => "UTC" irb(main):002:0> ENV["TZ"]="JST" => "JST" irb(main):003:0> Time.new.zone => "UTC" irb(main):004:0> ENV["TZ"]="PST" => "PST" irb(main):005:0> Time.new.zone => "UTC" irb(main):006:0> ENV["TZ"]="PST+8" => "PST+8" irb(main):007:0> Time.new.zone => "PST" ftw PST and JST get ignored, but "PST+8" gets accepted as PST? ok i guess... we need a +X so hacking gives: irb(main):003:0> ENV["TZ"]="JST+0" => "JST+0" irb(main):004:0> Time.new.zone => "JST" irb(main):005:0> Time.now.localtime => Tue Jan 04 06:41:55 +0000 2011 ok, but the time hasnt changed, so JST is still not recognized... http://www.timeanddate.com/library/abbreviations/timezones/ then as PST: irb(main):008:0> Time.now => Mon Jan 03 22:32:51 -0800 2011 irb(main):009:0> Time.now.utc => Tue Jan 04 06:32:55 UTC 2011 irb(main):011:0> Time.now.localtime => Mon Jan 03 22:33:01 -0800 2011 irb(main):012:0> ## so any Time.now defaults to localtime? [dc@fox:~]$ export TZ=JST [dc@fox:~]$ echo $TZ JST [dc@fox:~]$ irb irb(main):001:0> ENV['TZ'] => "JST" irb(main):002:0> Time.now.zone => "UTC" irb(main):003:0> but cannot be passed via the shell. so by conclusion it seems i can get PST and GMT timezones, but not japan. also the calculation methods to convert timezones seem broken. do i need to use other libs to deal with timezones effectively? tx, /dc __________________________________ David 'DC' Collier Pikkle 株式会社 取締役社長 dc / pikkle.com +81 (0)80-2037-1965 募集中! http://pikkle.com/company/hiring __________________________________