Using strftime
Introduction
The strftime format is the standard date formatting for UNIX. It's used in C, Ruby, and more.
- strftime specification (pubs.opengroup.org)
Unix date
date +%Y-%m-%d
date +'%A, %B %e, %Y'
The POSIX date command uses the same format codes as strftime.
See: POSIX strftime
Ruby
Format codes
Presets
Date
| Example | Output |
|---|---|
%m/%d/%Y | 06/05/2013 |
%F | 2013-06-05 |
%b %e %a | Jun 5 Wed |
Time
| Example | Output |
|---|---|
%I:%M %p | 11:05 PM |
%T | 23:05:00 |
See: strftime
Date tokens
| Token | Output | Description |
|---|---|---|
%a | Sun | Weekday, short |
%A | Sunday | Weekday, full |
%w | 0..6 | Weekday, Sunday is 0 |
%y | 13 | Year, two digits |
%Y | 2013 | Year, four digits |
%b | Jan | Month name, short |
%B | January | Month name, full |
%m | 01..12 | Month, two digits |
%d | 01..31 | Day, two digits |
%e | 1..31 | Day, space-padded |
See: strftime
Time tokens
| Token | Output | Description |
|---|---|---|
%l | 1 | Hour, 12-hour, space-padded |
%H | 00..23 | Hour, 24-hour, two digits |
%I | 01..12 | Hour, 12-hour, two digits |
%M | 00..59 | Minute, two digits |
%S | 00..60 | Second, two digits |
%p | AM | Meridiem |
%Z | UTC | Zone name |
%z | +0000 | Numeric offset |
%j | 001..366 | Day of year |
%s | 1370473500 | Unix timestamp, seconds |
%% | % | Literal percent sign |
See: strftime
0 Comments for this cheatsheet. Write yours!