NSDateFormatter Date Format Cheat Sheet
Below is a cheat sheet table for the most common formats needed by NSDateDateFormatter. I found I needed this way to often and always resorted to googling it so here it is for my reference and yours, bookmark it, save it.
Year
Format | Description | Example | |
---|---|---|---|
Input | Output | ||
y | Year, no padding. | 1 20 2016 |
1 20 2016 |
yy | Year with 2 digits. Pads with zeros if necessary. | 1 20 2016 |
01 20 2013 |
yyy | Year with 3 digits. Pads with zeros if necessary. | 1 20 2016 |
001 020 2016 |
yyyy | Year with 4 digits. Pads with zeros if necessary. | 1 20 2016 |
0001 0020 2016 |
Month
Format | Description | Example | |
---|---|---|---|
Input | Output | ||
M | Numeric month of the year, can be 1 digit. | June 1 |
6 1 |
MM | Numeric month of the year, always 2 digits. | June 1 |
06 01 |
MMM | Three letter abbreviation of the month. | June 1 |
Jun Jan |
MMMM | The full name of the month. | June 1 |
June January |
MMMMM | One letter abbreviation of the month. Not unique. | June 1 |
J J |
Day
Format | Description | Example | |
---|---|---|---|
Input | Output | ||
d | A day of the month, can be 1 digit. | 5 27 |
5 27 |
dd | A day of the month, 2 digits. Pads with zeros if necessary. | 5 27 |
05 27 |
E EE EEE |
Three letter abbreviation of the day. | Tuesday Friday |
Tue Fri |
EEEE | The full name of the day. | Tue Fri |
Tuesday Friday |
EEEEE | One letter abbreviation of the day. Not unique. | Tuesday Thursday Friday |
T T F |
EEEEEEE | Two letter abbreviation of the day. | Tuesday Friday |
Tu Fr |
F | Day of the week and the month. | 04/03/2016 Note format is: DD/MM/YYYY |
4th Monday in April |
Hour
Format | Description | Example | |
---|---|---|---|
Input | Output | ||
m | The minute, can be 1 digit. | 1 21 |
1 2 |
mm | The minute, pads with zeros if necessary. | 1 21 |
01 21 |
s | The second, can be 1 digit. | 7 30 |
7 30 |
ss | The second, pads with zeros if necessary. | 7 30 |
07 30 |
You can also see additional information on the formatting here.