NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd"];
I’ve enjoyed PHP’s date() documentation but have yet to find comprehensive documentation for NSDateFormatter. I have not verified all of the following so if you find an error, leave a comment and I’ll try to get it fixed as quickly as possible. A ton of this information was gathered from Alex Curylo.
| Character | Description | Example Returned Value |
|---|---|---|
| a | Ante Meridiem and Post Meridiem | AM/PM |
| A | Millisecond of the Day | 0..86399999 |
| c/cc | Numeric representation of day of the week | 1..7 |
| ccc | Abbreviated day of the week | Sun, Mon, Tue… |
| cccc | Written day of the week | Sunday, Monday, Tuesday… |
| d | 0 padded Day of Month | 1..31 |
| D | 0 padded Day of Year | 01..366 |
| e | Day of Week with leading zero | 01..07 |
| E..EEE | Sun, Mon, Tue… | |
| EEEE | Sunday, Monday, Tuesday… | |
| F | Week of Month, first day of week = Monday, with leading zero | 1..5 |
| g | Julian Day Number (number of days since 4713 BC January 1) | |
| G..GGG | Era Designator Abbreviated | BC, AD |
| GGGG | Era Designator | Before Christ, Anno Domini |
| h | Hour (12 hr) with leading zero | 1..12 |
| H | Hour (24 hr, starting at 0) with leading zero | 0..23 |
| k | Hour (24 hr, starting at 1) with leading zero | 1..24 |
| K | Hour (12 hr) with leading zero | 0..11 |
| m | Minute with leading zero | 0..59 |
| s | Second with leading zero | 0..59 |
| S | Rounded sub-second | |
| v..vvv | General GMT Timezone Abbreviation | GMT |
| vvvv | General GMT Timezone Name | Atlantic/Azores |
| z..zzz | Specific GMT Timezone Abbreviation | |
| zzzz | Specific GMT Timezone Name | |
| Z | RFC 822 Timezone | +0000 |
| L..LL | Month with leading 0 | 01..12 |
| LLL | Month abbreviation | Jan, Feb, Mar… |
| LLLL | Full Month | January, February, March… |
| w | Week of Year, 1st day of week is Sunday, 1st week of year starts from the last Sunday of last year, with leading zero | 01..53 |
| W | Week of Month, 1st day of week = Sunday, with leading 0 | 01..05 |
| M..MM | Month of the year | 1..12 |
| MMM | Month Abbreviated | Jan, Feb, Mar… |
| MMMM | Full Month | January, February, March… |
| q..qq | Quarter of the year | 1..4 |
| qqq | Quarter abbreviated | Q1, Q2, Q3, Q4 |
| qqqq | Quarter written out | 1st quarter, 2nd quarter, 3rd quarter… |
| Q..QQ | Quarter of the year | 1..4 |
| QQQ | Quarter abbreviated | Q1, Q2, Q3, Q4 |
| QQQQ | Quarter written out | 1st quarter, 2nd quarter, 3rd quarter… |
| y/yyyy | Full Year | 2012, 2013, 2014… |
| yy..yyy | 2 Digits Year | 12, 13, 14… |
| Y/YYYY | Full Year, starting from the Sunday of the 1st week of year | 2012, 2013, 2014… |
| YY/YYY | 2 Digits Year, starting from the Sunday of the 1st week of year | |
| u | Year |