NSDate
suggest changeSyntax
NSDate()creates anNSDatefor the current date and time.NSDate().timeIntervalSince1970is the number of seconds since 00:00:00 UTC on 1 January 1970.compare(_:)returns anNSComparisonResult. The argument has no external name:NSDate().compare(otherDate).
Remarks
These are date-format patterns. The month and weekday names below are English examples; other locales use different words. A zero-padded field such as MM is two digits, not “at least two.”
| Format | Meaning | Example 1 | Example 2 |
|---|---|---|---|
| y | A year with at least 1 digit. | 175 AD → “175” | 2016 AD → “2016” |
| yy | A year with exactly 2 digits. | 5 AD → “05” | 2016 AD → “16” |
| yyy | A year with at least 3 digits. | 5 AD → “005” | 2016 AD → “2016” |
| yyyy | A year with at least 4 digits. | 5 AD → “0005” | 2016 AD → “2016” |
| M | A month with at least 1 digit. | July → “7” | November → “11” |
| MM | A month with exactly 2 digits. | July → “07” | November → “11” |
| MMM | Three-letter month abbreviation. | July → “Jul” | November → “Nov” |
| MMMM | Full month name. | July → “July” | November → “November” |
| MMMMM | One-letter month abbreviation. January, June, and July can all be “J”. | July → “J” | November → “N” |
| d | Day with at least 1 digit. | 8 → “8” | 29 → “29” |
| dd | Day with exactly 2 digits. | 8 → “08” | 29 → “29” |
| E, EE, or EEE | Three-letter weekday abbreviation. | Monday → “Mon” | Thursday → “Thu” |
| EEEE | Full weekday name. | Monday → “Monday” | Thursday → “Thursday” |
| EEEEE | One-letter weekday. Thursday and Tuesday can both be “T”. | Monday → “M” | Thursday → “T” |
| EEEEEE | Two-letter weekday abbreviation. | Monday → “Mo” | Thursday → “Th” |
| a | Period of day (AM/PM). | 10 PM → “PM” | 2 AM → “AM” |
| h | A 1–12 hour with at least 1 digit. | 10 PM → “10” | 2 AM → “2” |
| hh | A 1–12 hour with exactly 2 digits. | 10 PM → “10” | 2 AM → “02” |
| H | A 0–23 hour with at least 1 digit. 10 PM is 22, not 14. | 10 PM → “22” | 2 AM → “2” |
| HH | A 0–23 hour with exactly 2 digits. | 10 PM → “22” | 2 AM → “02” |
| m | A minute with at least 1 digit. | 7 → “7” | 29 → “29” |
| mm | A minute with exactly 2 digits. | 7 → “07” | 29 → “29” |
| s | A second with at least 1 digit. | 7 → “7” | 29 → “29” |
| ss | A second with exactly 2 digits. | 7 → “07” | 29 → “29” |
There are more patterns, including zone (z) and fractional seconds (S).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents