From: Arlen Cuss Date: 2012-12-10T15:02:33+09:00 Subject: Re: Time.new(2001, 12, 3).to_i returns wrong value (In other words: the value is correct, and Time.at will provide you with the correct time (note that Time.at(x).to_i == x, whatever your local timezone), so I suggest you just ensure you're putting the right data in, and pay close attention to the pretty-printed Time values' timezones. On Monday, 10 December 2012 at 5:01 PM, Arlen Cuss wrote: > Time internally stores the value in UTC, as does #to_i properly return the seconds since the epoch; the issue here is in your construction of it: the default is to use your local timezone. > > I'm in +11, hence: > > > > Time.new(2001, 12, 3) > => 2001-12-03 00:00:00 +1100 > > > Time.new(2001, 12, 3).to_i > > > > > > => 1007298000 > > > Time.new(2001, 12, 3, 0, 0, 0, 0) > > > > > > => 2001-12-03 00:00:00 +0000 > > > Time.new(2001, 12, 3, 0, 0, 0, 0).to_i > > > > > > => 1007337600 > > > > On Monday, 10 December 2012 at 2:10 AM, Robert Buck wrote: > > > I basically subtracted the timezone offset for Time.new from my C code > > and that fixed it all regardless of what default timezone is set. > > > > -- > > Posted via http://www.ruby-forum.com/. >