I finally decided that I was going to write down my favorite strftime masks that I like to use when writing Ruby scripts.

Date Pattern   strftime Mask
YYMMDD -> “%y%m%d”
YYYYMMDD -> “%Y%m%d”
YYYYMMDD_HHMMSS -> “%Y%m%d_%H%M%S”
mm/dd/yyyy -> “%m/%m/%Y”

One can also use this Ruby script to show all of the possible formats string.

today = Time.now
codes = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a

puts "Ruby Version #{RUBY_PLATFORM} #{RUBY_VERSION}"
puts "strftime code mappings for #{today}"
codes.each do |code|
  scode = "%#{code}"
  puts "\"#{scode}\" --> #{today.strftime(scode)}"
end

Running the above code will generate the following result on my Mac.

Ruby Version universal.x86_64-darwin13 2.0.0
strftime code mappings for 2014-09-21 14:49:52 -0500
"%A" --> Sunday
"%B" --> September
"%C" --> 20
"%D" --> 09/21/14
"%E" --> %E
"%F" --> 2014-09-21
"%G" --> 2014
"%H" --> 14
"%I" --> 02
"%J" --> %J
"%K" --> %K
"%L" --> 858
"%M" --> 49
"%N" --> 858958000
"%O" --> %O
"%P" --> pm
"%Q" --> %Q
"%R" --> 14:49
"%S" --> 52
"%T" --> 14:49:52
"%U" --> 38
"%V" --> 38
"%W" --> 37
"%X" --> 14:49:52
"%Y" --> 2014
"%Z" --> CDT
"%a" --> Sun
"%b" --> Sep
"%c" --> Sun Sep 21 14:49:52 2014
"%d" --> 21
"%e" --> 21
"%f" --> %f
"%g" --> 14
"%h" --> Sep
"%i" --> %i
"%j" --> 264
"%k" --> 14
"%l" -->  2
"%m" --> 09
"%n" -->
"%o" --> %o
"%p" --> PM
"%q" --> %q
"%r" --> 02:49:52 PM
"%s" --> 1411328992
"%t" -->
"%u" --> 7
"%v" --> 21-SEP-2014
"%w" --> 0
"%x" --> 09/21/14
"%y" --> 14
"%z" --> -0500

– Chris