method
strftime
Related methods
- Class methods (100)
- ajd_to_amjd (<= v1_8_7_330)
- ajd_to_jd (<= v1_8_7_330)
- amjd_to_ajd (<= v1_8_7_330)
- civil
- civil_to_jd (<= v1_8_7_330)
- commercial
- commercial_to_jd (<= v1_8_7_330)
- complete_frags
- day_fraction_to_time (<= v1_8_7_330)
- deprecated_alias (<= v1_8_7_330)
- deprecated_class_method_alias (<= v1_8_7_330)
- fix_style (<= v1_8_7_330)
- gregorian? (<= v1_8_7_330)
- gregorian_leap?
- httpdate
- _httpdate
- iso8601
- _iso8601
- jd
- jd_to_ajd (<= v1_8_7_330)
- jd_to_civil (<= v1_8_7_330)
- jd_to_commercial (<= v1_8_7_330)
- jd_to_ld (<= v1_8_7_330)
- jd_to_mjd (<= v1_8_7_330)
- jd_to_ordinal (<= v1_8_7_330)
- jd_to_wday (<= v1_8_7_330)
- jd_to_weeknum (<= v1_8_7_330)
- jisx0301
- _jisx0301
- json_create
- julian? (<= v1_8_7_330)
- julian_leap?
- ld_to_jd (<= v1_8_7_330)
- leap?
- _load (>= v1_8_6_287)
- mjd_to_jd (<= v1_8_7_330)
- new
- new!
- new_by_frags
- now
- nth_kday
- num_pattern?
- once
- ordinal
- ordinal_to_jd (<= v1_8_7_330)
- parse
- _parse
- _parse_beat (<= v1_8_6_287)
- _parse_day
- _parse_ddd
- _parse_dot
- _parse_eu
- _parse_iso
- _parse_iso2
- _parse_jis
- _parse_mday
- _parse_mon
- _parse_sla
- _parse_sla_eu (<= v1_8_6_287)
- _parse_sla_ja (<= v1_8_6_287)
- _parse_sla_us (<= v1_8_6_287)
- _parse_time
- _parse_us
- _parse_vms
- _parse_year
- rewrite_frags
- rfc2822
- _rfc2822
- rfc3339
- _rfc3339
- rfc822
- _rfc822
- s3e
- strptime
- _strptime
- _strptime_i
- test_all (>= v2_6_3)
- test_civil (>= v2_6_3)
- test_commercial (>= v2_6_3)
- test_nth_kday (>= v2_6_3)
- test_ordinal (>= v2_6_3)
- test_unit_conv (>= v2_6_3)
- test_weeknum (>= v2_6_3)
- time_to_day_fraction (<= v1_8_7_330)
- today
- valid_civil?
- valid_commercial?
- valid_date?
- valid_date_frags?
- valid_jd?
- valid_nth_kday?
- valid_ordinal?
- valid_time?
- valid_time_frags?
- valid_weeknum?
- weeknum
- weeknum_to_jd (<= v1_8_7_330)
- xmlschema
- _xmlschema
- zone_to_diff (<= v1_8_7_330)
- Instance methods (167)
- <<
- <=>
- == (>= v1_9_2_180)
- ===
- >>
- -
- -@ (>= v1_9_2_180)
- / (>= v1_9_2_180)
- * (>= v1_9_2_180)
- ** (>= v1_9_2_180)
- % (>= v1_9_2_180)
- +
- +@ (>= v1_9_2_180)
- abs (>= v1_9_2_180)
- ajd
- ajd_to_amjd
- ajd_to_jd
- amjd
- amjd_to_ajd
- asctime
- as_json (>= v1_9_3_125)
- ceil (>= v1_9_2_180)
- civil
- civil_to_jd
- coerce (>= v1_9_2_180)
- commercial
- commercial_to_jd
- ctime
- cwday
- cweek
- cwyear
- day
- day_fraction
- day_fraction_to_time
- div (>= v1_9_2_180)
- divmod (>= v1_9_2_180)
- downto
- _dump (<= v1_8_7_330)
- dx_addsub (>= v1_9_2_180)
- dx_conv0 (>= v1_9_2_180)
- dx_conv1 (>= v1_9_2_180)
- dx_muldiv (>= v1_9_2_180)
- emit
- emit_a
- emit_ad
- emit_au
- emit_n
- emit_sn
- emit_w
- emit_z
- england
- eql?
- fill (>= v2_6_3)
- find_fdom
- find_fdoy
- find_ldom
- find_ldoy
- fix_style
- floor (>= v1_9_2_180)
- friday? (>= v1_9_3_125)
- gregorian
- gregorian?
- hash
- hour
- httpdate
- initialize_copy (>= v1_9_3_125)
- inspect
- inspect_raw (>= v2_6_3)
- integer? (>= v1_9_2_180)
- iso8601
- italy
- jd
- jd_to_ajd
- jd_to_civil
- jd_to_commercial
- jd_to_ld
- jd_to_mjd
- jd_to_nth_kday
- jd_to_ordinal
- jd_to_wday
- jd_to_weeknum
- jisx0301
- julian
- julian?
- ld
- ld_to_jd
- leap?
- marshal_dump
- marshal_dump_old (>= v2_6_3)
- marshal_load
- mday
- min
- minute
- mjd
- mjd_to_jd
- modulo (>= v1_9_2_180)
- mon
- monday? (>= v1_9_3_125)
- month
- new_offset
- new_start
- next
- next_day
- next_month
- next_year
- nth_kday?
- nth_kday_to_jd
- offset
- ordinal
- ordinal_to_jd
- prev_day
- prev_month
- prev_year
- quo (>= v1_9_2_180)
- quotient (>= v1_9_2_180)
- quotrem (>= v1_9_2_180)
- remainder (>= v1_9_2_180)
- rfc2822
- rfc3339
- rfc822
- round (>= v1_9_2_180)
- saturday? (>= v1_9_3_125)
- sec
- sec_fraction
- second
- second_fraction
- start
- step
- strftime
- succ
- sunday? (>= v1_9_3_125)
- thursday? (>= v1_9_3_125)
- time
- time_to_day_fraction
- to_c (>= v1_9_2_180)
- to_date
- to_datetime
- to_f (>= v1_9_2_180)
- to_i (>= v1_9_2_180)
- to_int (>= v1_9_2_180)
- to_json
- to_r (>= v1_9_2_180)
- to_s
- to_time
- to_yaml
- truncate (>= v1_9_2_180)
- tuesday? (>= v1_9_3_125)
- upto
- _valid_civil?
- _valid_commercial?
- _valid_jd?
- _valid_nth_kday?
- _valid_ordinal?
- _valid_time?
- _valid_weeknum?
- wday
- wednesday? (>= v1_9_3_125)
- weeknum0
- weeknum1
- weeknum_to_jd
- wnum0
- wnum1
- xmlschema
- yday
- year
- zone
- zone_to_diff
= private
= protected
strftime(fmt='%F')
public
No documentation
This method has no description. You can help the Ruby community by adding new notes.
Show source
# File lib/date/format.rb, line 215 def strftime(fmt='%F') fmt.gsub(/%([-_0^#]+)?(\d+)?([EO]?(?::{1,3}z|.))/) do f = {} m = $& s, w, c = $1, $2, $3 if s s.scan(/./) do |k| case k when '-'; f[:p] = '-' when '_'; f[:p] = "\s" when '0'; f[:p] = '0' when '^'; f[:u] = true when '#'; f[:x] = true end end end if w f[:w] = w.to_i end case c when 'A'; emit_ad(DAYNAMES[wday], 0, f) when 'a'; emit_ad(ABBR_DAYNAMES[wday], 0, f) when 'B'; emit_ad(MONTHNAMES[mon], 0, f) when 'b'; emit_ad(ABBR_MONTHNAMES[mon], 0, f) when 'C', 'EC'; emit_sn((year / 100).floor, 2, f) when 'c', 'Ec'; emit_a(strftime('%a %b %e %H:%M:%S %Y'), 0, f) when 'D'; emit_a(strftime('%m/%d/%y'), 0, f) when 'd', 'Od'; emit_n(mday, 2, f) when 'e', 'Oe'; emit_a(mday, 2, f) when 'F' if m == '%F' format('%.4d-%02d-%02d', year, mon, mday) # 4p else emit_a(strftime('%Y-%m-%d'), 0, f) end when 'G'; emit_sn(cwyear, 4, f) when 'g'; emit_n(cwyear % 100, 2, f) when 'H', 'OH'; emit_n(hour, 2, f) when 'h'; emit_ad(strftime('%b'), 0, f) when 'I', 'OI'; emit_n((hour % 12).nonzero? || 12, 2, f) when 'j'; emit_n(yday, 3, f) when 'k'; emit_a(hour, 2, f) when 'L' f[:p] = nil w = f[:w] || 3 u = 10**w emit_n((sec_fraction * u).floor, w, f) when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f) when 'M', 'OM'; emit_n(min, 2, f) when 'm', 'Om'; emit_n(mon, 2, f) when 'N' f[:p] = nil w = f[:w] || 9 u = 10**w emit_n((sec_fraction * u).floor, w, f) when 'n'; emit_a("\n", 0, f) when 'P'; emit_ad(strftime('%p').downcase, 0, f) when 'p'; emit_au(if hour < 12 then 'AM' else 'PM' end, 0, f) when 'Q' s = ((ajd - UNIX_EPOCH_IN_AJD) / MILLISECONDS_IN_DAY).round emit_sn(s, 1, f) when 'R'; emit_a(strftime('%H:%M'), 0, f) when 'r'; emit_a(strftime('%I:%M:%S %p'), 0, f) when 'S', 'OS'; emit_n(sec, 2, f) when 's' s = ((ajd - UNIX_EPOCH_IN_AJD) / SECONDS_IN_DAY).round emit_sn(s, 1, f) when 'T' if m == '%T' format('%02d:%02d:%02d', hour, min, sec) # 4p else emit_a(strftime('%H:%M:%S'), 0, f) end when 't'; emit_a("\t", 0, f) when 'U', 'W', 'OU', 'OW' emit_n(if c[-1,1] == 'U' then wnum0 else wnum1 end, 2, f) when 'u', 'Ou'; emit_n(cwday, 1, f) when 'V', 'OV'; emit_n(cweek, 2, f) when 'v'; emit_a(strftime('%e-%b-%Y'), 0, f) when 'w', 'Ow'; emit_n(wday, 1, f) when 'X', 'EX'; emit_a(strftime('%H:%M:%S'), 0, f) when 'x', 'Ex'; emit_a(strftime('%m/%d/%y'), 0, f) when 'Y', 'EY'; emit_sn(year, 4, f) when 'y', 'Ey', 'Oy'; emit_n(year % 100, 2, f) when 'Z'; emit_au(strftime('%:z'), 0, f) when /\A(:{0,3})z/ t = $1.size sign = if offset < 0 then -1 else +1 end fr = offset.abs ss = fr.div(SECONDS_IN_DAY) # 4p hh, ss = ss.divmod(3600) mm, ss = ss.divmod(60) if t == 3 if ss.nonzero? then t = 2 elsif mm.nonzero? then t = 1 else t = -1 end end case t when -1 tail = [] sep = '' when 0 f[:w] -= 2 if f[:w] tail = ['%02d' % mm] sep = '' when 1 f[:w] -= 3 if f[:w] tail = ['%02d' % mm] sep = ':' when 2 f[:w] -= 6 if f[:w] tail = ['%02d' % mm, '%02d' % ss] sep = ':' end ([emit_z(sign * hh, 2, f)] + tail).join(sep) when '%'; emit_a('%', 0, f) when '+'; emit_a(strftime('%a %b %e %H:%M:%S %Z %Y'), 0, f) else m end end end
Register or
log in
to add new notes.
roryokane -
June 28, 2012
0 thanks
see also – similar methods
See also Time#strftime and DateTime#strftime . (They work similarly, but have different APIdock notes.)
panzi -
May 16, 2013
0 thanks
Bug in Ruby or this documentation
%Q doesn’t return microseconds but milliseconds! Use %s%6N for microseconds.