Module | ActiveSupport::CoreExtensions::DateTime::Conversions |
In: |
lib/active_support/core_ext/date_time/conversions.rb
|
Getting datetimes in different convenient string representations and other objects
Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000"
Convert to a formatted string - see DATE_FORMATS for predefined formats. You can also add your own formats to the DATE_FORMATS constant and use them with this method.
This method is also aliased as to_s.
datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000 datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00" datetime.to_s(:db) # => "2007-12-04 00:00:00" datetime.to_s(:number) # => "20071204000000" datetime.to_formatted_s(:short) # => "04 Dec 00:00" datetime.to_formatted_s(:long) # => "December 04, 2007 00:00" datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00" datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"