On 32bit systems, the maximum representable
Time
Show archive.org snapshot
is 2038-01-19 03:14:07
in UTC or 2038-01-19 04:14:07
in CET. If you try to instantiate a Time
with any later value, Ruby will raise an ArgumentError
.
If you need to represent later time values, use the
DateTime
Show archive.org snapshot
class. This is also what Rails does when it loads a record from the database that has a DATETIME value which Time
cannot represent. Note that there are some
subtle differences
Show archive.org snapshot
between the APIs of Time
and DateTime
. Also DateTime
is implemented in Ruby, while Time
is implemented in C, making Time
much more performant. So don't always use DateTime
because it's more awesome all of the time, because it is not.
Our favorite time travel gem
Timecop
Show archive.org snapshot
works with both Time
and DateTime
.