instance method to_fs

Ruby on Rails 7.2.3

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

to_fs(format = :default)

Returns a string of the object’s date and time.

This method is aliased to to_formatted_s.

Accepts an optional format:

  • :default - default value, mimics Ruby Time#to_s format.

  • :db - format outputs time in UTC :db time. See Time#to_fs(:db).

  • Any key in Time::DATE_FORMATS can be used. See active_support/core_ext/time/conversions.rb.

Parameters

format opt = :default
Source
# File activesupport/lib/active_support/time_with_zone.rb, line 212
    def to_fs(format = :default)
      if format == :db
        utc.to_fs(format)
      elsif formatter = ::Time::DATE_FORMATS[format]
        formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
      else
        # Change to to_s when deprecation is gone.
        "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}"
      end
    end

Defined in activesupport/lib/active_support/time_with_zone.rb line 212 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::TimeWithZone

Type at least 2 characters to search.

↑↓ navigate · open · esc close