instance method
to_s
Ruby on Rails 4.2.9
Since v2.2.3Signature
to_s(format = :default)
Returns a string of the object’s date and time. Accepts an optional format:
-
:default- default value, mimics Ruby 1.9 Time#to_s format. -
:db- format outputs time in UTC :db time. See Time#to_formatted_s(:db). -
Any key in
Time::DATE_FORMATScan be used. See active_support/core_ext/time/conversions.rb.
Parameters
-
formatopt = :default
Source
# File activesupport/lib/active_support/time_with_zone.rb, line 198
def to_s(format = :default)
if format == :db
utc.to_s(format)
elsif formatter = ::Time::DATE_FORMATS[format]
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
else
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format
end
end
Defined in activesupport/lib/active_support/time_with_zone.rb line 198
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::TimeWithZone