instance method
strftime
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
strftime(format, utc = Time.now.utc)
Converts a time in UTC to local time and returns it as a string according to the given format. The formatting is identical to Time.strftime and DateTime.strftime, except %Z is replaced with the timezone abbreviation for the specified time (for example, EST or EDT).
Parameters
-
formatreq -
utcopt = Time.now.utc
Source
# File activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb, line 448
def strftime(format, utc = Time.now.utc)
period = period_for_utc(utc)
local = period.to_local(utc)
local = Time.at(local).utc unless local.kind_of?(Time) || local.kind_of?(DateTime)
abbreviation = period.abbreviation.to_s.gsub(/%/, '%%')
format = format.gsub(/(.?)%Z/) do
if $1 == '%'
# return %%Z so the real strftime treats it as a literal %Z too
'%%Z'
else
"#$1#{abbreviation}"
end
end
local.strftime(format)
end
Defined in activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb line 448
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in TZInfo::Timezone