Methods
to_date
to_datetime
Public Instance methods
Converts a Time object to a Date, dropping hour, minute, and second precision.
my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007 my_time.to_date # => Mon, 12 Nov 2007 your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009 your_time.to_date # => Tue, 13 Jan 2009
[ + ]
# File lib/lore/facets/date.rb, line 353 def to_date ::Date.new(year, month, day) end
Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007 my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500 your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009 your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500
[ + ]
# File lib/lore/facets/date.rb, line 374 def to_datetime ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) end