Skip to content

Instantly share code, notes, and snippets.

@chrisvanhill
Created March 17, 2011 10:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvanhill/874130 to your computer and use it in GitHub Desktop.
Save chrisvanhill/874130 to your computer and use it in GitHub Desktop.
Ruby date and time formats
Letter Output Example
%A full day of week
%a abbrev day of week
%B full month name
%b abbrev month name
%C century (first two digits of year)
%c Day, month, time. year Thu Mar 17 11:20:10 2011
%D western format with slashes mm/dd/yy
%d day of month (zero-padded) 02
%e day of month (space-padded) _2
%F Year-month-day (with dash) yyyy-mm-dd
%G 4-digit year
%g 2-digit year
%H Hour (24 hour format)
%h abbrev month
%I hour (12 hour format)
%j day of year (number of days since Jan 1)
%k hour (24 hour format)
%l hour (12 hour format space padded)
%M minute
%m month (zero padded)
%n newline
%P am or pm (lowercase)
%p AM or PM (uppercase)
%Q milli-seconds since unix epoch (Jan 1 1970)
%R hour:minute 11:20
%r hour:minute:second AM/PM 11:20:10 AM
%S seconds
%s seconds since unix epoch (Jan 1 1970)
%u weekday as a decimal number
%U week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week 21
%V The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. 22
%W week number of the current year as a decimal number, starting with the first Monday as the first day of the first week 21
%w day of the week as a decimal, Sunday being 0, Saturday being 6
%x preferred date representation for the current locale without the time
%X preferred time representation for the current locale without the date
%y year as a decimal number without a century (range 00 to 99)
%Y year as a decimal number including the century
%Z time zone abbreviation CET
%z timezone offset to GMT +0100
%% literal `%’ character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment