From: Brian Candler Date: 2012-12-12T01:26:24+09:00 Subject: Re: Time.new(2001, 12, 3).to_i returns wrong value Robert Buck wrote in post #1088400: > Time.new(2001, 12, 3).to_i > > According to international standards this OUGHT to return 1007337600, > but no, it returns 1007355600, despite the Ruby documentation stating > that the to_i method is supposed to return seconds since the Epoch. It does construct the epoch time, but in this case interprets the Y/M/D you are passing in as for midnight in the local timezone. Just use the method which does what you want, which in this case is Time.gm >> ENV['TZ']="Etc/GMT-5" => "Etc/GMT-5" >> a = Time.mktime(2001,12,3) => Mon Dec 03 00:00:00 +0500 2001 >> a.to_i => 1007319600 >> b = Time.gm(2001,12,3) => Mon Dec 03 00:00:00 UTC 2001 >> b.to_i => 1007337600 [tested with ruby 1.8] -- Posted via http://www.ruby-forum.com/.