strftime - Ruby on Rails Date Formats

strftime is used in C, C++, PHP, Rails, Ruby and Python to name a few. Here is a list of what means what when constructing a date string format.

Not sure which date format to use? I've got you sorted (by providing the following link). Xkcd says it best.

TL;DR
IS0 8601
%Y-%m-%d
RubyTime.now.iso8601
RubyTime.now.strftime("%Y-%m-%d")
Golangtime.Now().Format("2006-01-02")

strftime - Ruby on Rails Date Formats

Words

DirectivesDescriptionExample
%aWeekday as locale’s abbreviated name.Mon
%AWeekday as locale’s full name.Monday
%bMonth as locale’s abbreviated name.Sep
%BMonth as locale’s full name.September
%pLocale’s equivalent of either AM or PM.AM

Day

DirectivesDescriptionExample
%wWeekday as a decimal number, where 0 is Sunday and 6 is Saturday.1
%dDay of the month as a zero-padded decimal number.30
%-dDay of the month as a decimal number. (Platform specific)30
%jDay of the year as a zero-padded decimal number.273
%-jDay of the year as a decimal number. (Platform specific)273

Month

DirectivesDescriptionExample
%mMonth as a zero-padded decimal number.09
%-mMonth as a decimal number. (Platform specific)9

Year

DirectivesDescriptionExample
%yYear without century as a zero-padded decimal number.13
%YYear with century as a decimal number.2013
%Ccentury number (year divided by 100)20

Week

DirectivesDescriptionExample
%UWeek number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.39
%WWeek number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.39

Time

DirectivesDescriptionExample
%HHour (24-hour clock) as a zero-padded decimal number.07
%-HHour (24-hour clock) as a decimal number. (Platform specific)7
%IHour (12-hour clock) as a zero-padded decimal number.07
%-IHour (12-hour clock) as a decimal number. (Platform specific)7
%MMinute as a zero-padded decimal number.06
%-MMinute as a decimal number. (Platform specific)6
%SSecond as a zero-padded decimal number.05
%-SSecond as a decimal number. (Platform specific)5
%fMicrosecond as a decimal number, zero-padded on the left.000000
%zUTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).
%ZTime zone name (empty string if the object is naive).

Misc

DirectivesDescriptionExample
%cLocale’s appropriate date and time representation.Mon Sep 30 07:06:05 2013
%xLocale’s appropriate date representation.09/30/13
%XLocale’s appropriate time representation.07:06:05
%%A Literal '%' character.%