Last active
December 16, 2015 15:49
-
-
Save otkrsk/5459124 to your computer and use it in GitHub Desktop.
How to format dates in Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %H - Hour of the day, 24-hour clock, zero-padded (00..23) | |
| %k - Hour of the day, 24-hour clock, blank-padded ( 0..23) | |
| %I - Hour of the day, 12-hour clock, zero-padded (01..12) | |
| %l - Hour of the day, 12-hour clock, blank-padded ( 1..12) | |
| %P - Meridian indicator, lowercase (``am'' or ``pm'') | |
| %p - Meridian indicator, uppercase (``AM'' or ``PM'') | |
| %M - Minute of the hour (00..59) | |
| 12:00PM = %I:%M%p | |
| Date (Year, Month, Day): | |
| %Y - Year with century (can be negative, 4 digits at least) | |
| -0001, 0000, 1995, 2009, 14292, etc. | |
| %m - Month of the year, zero-padded (01..12) | |
| %_m blank-padded ( 1..12) | |
| %-m no-padded (1..12) | |
| %B - The full month name (``January'') | |
| %^B uppercased (``JANUARY'') | |
| %b - The abbreviated month name (``Jan'') | |
| %^b uppercased (``JAN'') | |
| %h - Equivalent to %b | |
| %d - Day of the month, zero-padded (01..31) | |
| %-d no-padded (1..31) | |
| %e - Day of the month, blank-padded ( 1..31) | |
| e.g: Fri, 24 January, 2013 - %a, %m %B, %Y (need to implement logic to decide whether to put 'th' or 'st') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment