Advertisements
Date Snippet
NSDateFormatter is the class used for formatting dates in iOS. Following table shows the symbols and corresponding usage.
Symbol | Description for symbol |
yyyy | Year in full. eg. 2017 for 2017 and 0100 for 1st century (with prefix zeros if necessary) |
yy | Year in two digits. eg. 17 for 2017 |
y | Year in 4 digit. eg. 17 for 2017, 100 for 1st century(Year 0100) |
MMMM | Month in full. eg. November |
MMM | Month in 3 letters. eg. Nov. |
MM | Month in numbers. eg. 09 for Nov |
M | Month in numbers. eg. 9 for Nov |
MMMMM | Months first letter eg. N for Nov. |
dd | Day in numbers with prefix zero if necessary. Eg. 01 for 1. |
d | Day in numbers with no prefix zero. Eg. 1 for 1st January. |
h | Hour in 12 hour format with no prefix zero. Eg. 1 for 1 pm. |
hh | Hour in numbers with prefix zero if necessary. Eg. 01 pm for 1 pm. |
HH | Hour in 24 hour format with prefix zero if necessary. Eg. 09 for 09:00 hours. |
H | Hour in 24 hour format with no prefix zero. Eg. 9 for 09:00 hours |
a | AM or PM for 12 hour formats. |
m | Minutes in numbers with no prefix zero. Eg. 1 for 1 minute. |
mm | Minutes in numbers with prefix zeros if necessary. Eg. 01 for 1 minute. |
s | Seconds in numbers with no prefix zero. Eg. 1 for 1 second. |
ss | Seconds in numbers with prefix zeros if necessary. Eg. 01 for 1 second |
zzz | Timezone in 3 letters, example CST, PST, IST and so on. |
zzzz | Timezone in full, example Central Time Zone for CST. |
Z | RFC time zone format - eg. -06:00 |
ZZZZZ | ISO 8601 time zone format - eg. -06:00 |
E | Day in Short. eg W |
EEE | Day in 3 letters. eg Wed |
EEEE | Day in full. eg Wednesday |