method
strftime
Related methods
- Class methods (100)
- ajd_to_amjd
- ajd_to_jd
- amjd_to_ajd
- civil
- civil_to_jd
- commercial
- commercial_to_jd
- complete_frags
- day_fraction_to_time
- deprecated_alias (>= v1_8_7_72)
- deprecated_class_method_alias (>= v1_8_7_72)
- fix_style
- gregorian?
- gregorian_leap?
- httpdate (>= v1_9_1_378)
- _httpdate (>= v1_9_1_378)
- iso8601 (>= v1_9_1_378)
- _iso8601 (>= v1_9_1_378)
- jd
- jd_to_ajd
- jd_to_civil
- jd_to_commercial
- jd_to_ld
- jd_to_mjd
- jd_to_ordinal
- jd_to_wday
- jd_to_weeknum
- jisx0301 (>= v1_9_1_378)
- _jisx0301 (>= v1_9_1_378)
- json_create (>= v1_9_1_378)
- julian?
- julian_leap?
- ld_to_jd
- leap? (>= v1_9_1_378)
- _load
- mjd_to_jd
- new
- new! (>= v1_9_1_378)
- new_by_frags
- now
- nth_kday (>= v1_9_1_378)
- num_pattern?
- once
- ordinal
- ordinal_to_jd
- parse
- _parse
- _parse_beat
- _parse_day
- _parse_ddd
- _parse_dot (>= v1_8_7_72)
- _parse_eu
- _parse_iso
- _parse_iso2
- _parse_jis
- _parse_mday
- _parse_mon
- _parse_sla (>= v1_8_7_72)
- _parse_sla_eu
- _parse_sla_ja
- _parse_sla_us
- _parse_time
- _parse_us
- _parse_vms
- _parse_year
- rewrite_frags
- rfc2822 (>= v1_9_1_378)
- _rfc2822 (>= v1_9_1_378)
- rfc3339 (>= v1_9_1_378)
- _rfc3339 (>= v1_9_1_378)
- rfc822 (>= v1_9_1_378)
- _rfc822 (>= v1_9_1_378)
- 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
- today
- valid_civil?
- valid_commercial?
- valid_date? (>= v1_9_1_378)
- valid_date_frags?
- valid_jd?
- valid_nth_kday? (>= v1_9_1_378)
- valid_ordinal?
- valid_time?
- valid_time_frags?
- valid_weeknum?
- weeknum
- weeknum_to_jd
- xmlschema (>= v1_9_1_378)
- _xmlschema (>= v1_9_1_378)
- zone_to_diff
- 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 (>= v1_9_1_378)
- ajd_to_jd (>= v1_9_1_378)
- amjd
- amjd_to_ajd (>= v1_9_1_378)
- asctime
- as_json (>= v1_9_3_125)
- ceil (>= v1_9_2_180)
- civil
- civil_to_jd (>= v1_9_1_378)
- coerce (>= v1_9_2_180)
- commercial
- commercial_to_jd (>= v1_9_1_378)
- ctime
- cwday
- cweek
- cwyear
- day
- day_fraction
- day_fraction_to_time (>= v1_9_1_378)
- div (>= v1_9_2_180)
- divmod (>= v1_9_2_180)
- downto
- _dump
- 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 (>= v1_9_1_378)
- find_fdoy (>= v1_9_1_378)
- find_ldom (>= v1_9_1_378)
- find_ldoy (>= v1_9_1_378)
- fix_style
- floor (>= v1_9_2_180)
- friday? (>= v1_9_3_125)
- gregorian
- gregorian?
- hash
- hour
- httpdate (>= v1_9_1_378)
- initialize_copy (>= v1_9_3_125)
- inspect
- inspect_raw (>= v2_6_3)
- integer? (>= v1_9_2_180)
- iso8601 (>= v1_9_1_378)
- italy
- jd
- jd_to_ajd (>= v1_9_1_378)
- jd_to_civil (>= v1_9_1_378)
- jd_to_commercial (>= v1_9_1_378)
- jd_to_ld (>= v1_9_1_378)
- jd_to_mjd (>= v1_9_1_378)
- jd_to_nth_kday (>= v1_9_1_378)
- jd_to_ordinal (>= v1_9_1_378)
- jd_to_wday (>= v1_9_1_378)
- jd_to_weeknum (>= v1_9_1_378)
- jisx0301 (>= v1_9_1_378)
- julian
- julian?
- ld
- ld_to_jd (>= v1_9_1_378)
- leap?
- marshal_dump (>= v1_9_1_378)
- marshal_dump_old (>= v2_6_3)
- marshal_load (>= v1_9_1_378)
- mday
- min
- minute (>= v1_9_1_378)
- mjd
- mjd_to_jd (>= v1_9_1_378)
- modulo (>= v1_9_2_180)
- mon
- monday? (>= v1_9_3_125)
- month
- new_offset
- new_start
- next
- next_day
- next_month (>= v1_9_1_378)
- next_year (>= v1_9_1_378)
- nth_kday? (>= v1_9_1_378)
- nth_kday_to_jd (>= v1_9_1_378)
- offset
- ordinal
- ordinal_to_jd (>= v1_9_1_378)
- prev_day (>= v1_9_1_378)
- prev_month (>= v1_9_1_378)
- prev_year (>= v1_9_1_378)
- quo (>= v1_9_2_180)
- quotient (>= v1_9_2_180)
- quotrem (>= v1_9_2_180)
- remainder (>= v1_9_2_180)
- rfc2822 (>= v1_9_1_378)
- rfc3339 (>= v1_9_1_378)
- rfc822 (>= v1_9_1_378)
- round (>= v1_9_2_180)
- saturday? (>= v1_9_3_125)
- sec
- sec_fraction
- second (>= v1_9_1_378)
- second_fraction (>= v1_9_1_378)
- start
- step
- strftime
- succ
- sunday? (>= v1_9_3_125)
- thursday? (>= v1_9_3_125)
- time
- time_to_day_fraction (>= v1_9_1_378)
- to_c (>= v1_9_2_180)
- to_date (>= v1_9_1_378)
- to_datetime (>= v1_9_1_378)
- to_f (>= v1_9_2_180)
- to_i (>= v1_9_2_180)
- to_int (>= v1_9_2_180)
- to_json (>= v1_9_1_378)
- to_r (>= v1_9_2_180)
- to_s
- to_time (>= v1_9_1_378)
- to_yaml
- truncate (>= v1_9_2_180)
- tuesday? (>= v1_9_3_125)
- upto
- _valid_civil? (>= v1_9_1_378)
- _valid_commercial? (>= v1_9_1_378)
- _valid_jd? (>= v1_9_1_378)
- _valid_nth_kday? (>= v1_9_1_378)
- _valid_ordinal? (>= v1_9_1_378)
- _valid_time? (>= v1_9_1_378)
- _valid_weeknum? (>= v1_9_1_378)
- wday
- wednesday? (>= v1_9_3_125)
- weeknum0
- weeknum1
- weeknum_to_jd (>= v1_9_1_378)
- wnum0
- wnum1
- xmlschema (>= v1_9_1_378)
- yday
- year
- zone
- zone_to_diff (>= v1_9_1_378)
= 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 200 def strftime(fmt='%F') fmt.gsub(/%([-_0^#]+)?(\d+)?[EO]?(:{1,3}z|.)/m) do |m| f = {} 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'; emit_sn((year / 100).floor, 2, f) when 'c'; emit_a(strftime('%a %b %e %H:%M:%S %Y'), 0, f) when 'D'; emit_a(strftime('%m/%d/%y'), 0, f) when 'd'; emit_n(mday, 2, f) when 'e'; 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'; emit_n(hour, 2, f) when 'h'; emit_ad(strftime('%b'), 0, f) when 'I'; emit_n((hour % 12).nonzero? || 12, 2, f) when 'j'; emit_n(yday, 3, f) when 'k'; emit_a(hour, 2, f) when 'L' emit_n((sec_fraction / (1.to_r/86400/(10**3))).round, 3, f) when 'l'; emit_a((hour % 12).nonzero? || 12, 2, f) when 'M'; emit_n(min, 2, f) when 'm'; emit_n(mon, 2, f) when 'N' emit_n((sec_fraction / (1.to_r/86400/(10**9))).round, 9, f) when 'n'; "\n" 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' d = ajd - self.class.jd_to_ajd(self.class::UNIXEPOCH, 0) s = (d * 86400*10**3).to_i 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'; emit_n(sec, 2, f) when 's' d = ajd - self.class.jd_to_ajd(self.class::UNIXEPOCH, 0) s = (d * 86400).to_i 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'; "\t" when 'U', 'W' emit_n(if c == 'U' then wnum0 else wnum1 end, 2, f) when 'u'; emit_n(cwday, 1, f) when 'V'; emit_n(cweek, 2, f) when 'v'; emit_a(strftime('%e-%b-%Y'), 0, f) when 'w'; emit_n(wday, 1, f) when 'X'; emit_a(strftime('%H:%M:%S'), 0, f) when 'x'; emit_a(strftime('%m/%d/%y'), 0, f) when 'Y'; emit_sn(year, 4, f) when 'y'; 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 hh, fr = fr.divmod(1.to_r/24) mm, fr = fr.divmod(1.to_r/1440) ss, fr = fr.divmod(1.to_r/86400) 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) when '1' if $VERBOSE warn("warning: strftime: %1 is deprecated; forget this") end emit_n(jd, 1, f) when '2' if $VERBOSE warn("warning: strftime: %2 is deprecated; use '%Y-%j'") end emit_a(strftime('%Y-%j'), 0, f) when '3' if $VERBOSE warn("warning: strftime: %3 is deprecated; use '%F'") end emit_a(strftime('%F'), 0, f) else c 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.