Common time formats
Introduction
Date formatting tokens differ by tool: strftime for Ruby and date, Moment.js
tokens for JavaScript libraries that copy them.
- strftime format cheatsheet (devhints.io)
- Moment.js cheatsheet (devhints.io)
- strftime (pubs.opengroup.org)
strftime format
Presets
Date
| Example | Output |
|---|---|
%m/%d/%Y | 06/05/2013 |
%A, %B %e, %Y | Wednesday, June 5, 2013 |
%F | 2013-06-05 |
%b %e %a | Jun 5 Wed |
Time
| Example | Output |
|---|---|
%H:%M | 23:05 |
%I:%M %p | 11:05 PM |
%T | 23:05:00 |
Used by Ruby, UNIX date, and many more.
See: strftime
Date
| Symbol | Example | Area |
|---|---|---|
%a | Sun | Weekday |
%A | Sunday | |
%w | 0..6 (Sunday is 0) | |
%y | 13 | Year |
%Y | 2013 | |
%b | Jan | Month |
%B | January | |
%m | 01..12 | |
%d | 01..31 | Day |
%e | 1..31 |
See: strftime
Time
| Symbol | Example | Area |
|---|---|---|
%l | 1 | Hour |
%H | 00..23 | 24h hour |
%I | 01..12 | 12h hour |
%M | 00..59 | Minute |
%S | 00..60 | Second |
%p | AM | AM or PM |
%Z | UTC | Zone name |
%z | +0000 | Numeric offset |
%j | 001..366 | Day of the year |
%s | 1370473500 | Epoch seconds |
%% | % | Literal % character |
See: strftime
Moment.js format
Examples
Date
| Example | Output |
|---|---|
YYYY-MM-DD | 2014-01-01 |
dddd, MMMM Do YYYY | Friday, May 16th 2014 |
dddd [the] Do [of] MMMM | Friday the 16th of May |
Time
| Example | Output |
|---|---|
hh:mm a | 12:30 pm |
Moment.js tokens; date-fns and Java SimpleDateFormat use different ones. Moment itself is in maintenance mode.
See: Format
Date
| Symbol | Example | Area |
|---|---|---|
d | 0..6 | Weekday |
dd | Su | |
ddd | Sun | |
dddd | Sunday | |
YY | 13 | Year |
YYYY | 2013 | |
M | 1..12 (Jan is 1) | Month |
Mo | 1st..12th | |
MM | 01..12 (Jan is 1) | |
MMM | Jan | |
MMMM | January | |
Q | 1..4 | Quarter |
Qo | 1st..4th | |
D | 1..31 | Day |
Do | 1st..31st | |
DD | 01..31 | |
DDD | 1..365 | Day of year |
DDDo | 1st..365th | |
DDDD | 001..365 | |
w | 1..53 | Week of year |
wo | 1st..53rd | |
ww | 01..53 |
See: Format
Time
| Symbol | Example | Area |
|---|---|---|
H | 0..23 | 24h hour |
HH | 00..23 | |
h | 1..12 | 12h hour |
hh | 01..12 | |
m | 0..59 | Minutes |
mm | 00..59 | |
s | 0..59 | Seconds |
ss | 00..59 | |
a | am | AM/PM |
A | AM | |
Z | +07:00 | Zone offset |
ZZ | +0730 | |
S | 0..9 | Deciseconds |
SS | 00..99 | Centiseconds |
SSS | 000..999 | Milliseconds |
X | 1360013296 | Unix timestamp |
x | 1360013296123 | Unix ms timestamp |
See: Format
Presets
| Example | Output |
|---|---|
LT | 8:30 PM |
LTS | 8:30:25 PM |
LL | August 2, 1985 |
ll | Aug 2, 1985 |
LLL | August 2, 1985 8:30 PM |
lll | Aug 2, 1985 8:30 PM |
LLLL | Friday, August 2, 1985 8:30 PM |
llll | Fri, Aug 2, 1985 8:30 PM |
See: Long date formats
0 Comments for this cheatsheet. Write yours!