October 2006
Intermediate to advanced
888 pages
16h 55m
English
For various reasons we may want to convert back and forth between the internal (or traditional) measure and the standard date form. Internally, dates are stored as a number of seconds since the epoch.
The Time.at class method creates a new time given the number of seconds since the epoch:
epoch = Time.at(0) # Find the epoch (1 Jan 1970 GMT) newmil = Time.at(978307200) # Happy New Millennium! (1 Jan 2001) The inverse is the instance method to_i which converts to an integer. now = Time.now # 16 Nov 2000 17:24:28 sec = now.to_i # 974424268
If you need microseconds, and your system supports that resolution, you can use to_f to convert to a floating point number.
Read now
Unlock full access