Easy Skeezy Date Formatting for Swift and Objective-C

ISO 8601 format


Tuesday, Mar 31, 2020
EEEE, MMM d, yyyy
03-31-2020 15:49
MM-dd-yyyy HH:mm
Mar 31, 3:49 PM
MMM d, h:mm a
March 2020
MMMM yyyy
Mar 31, 2020
MMM d, yyyy
Tue, 31 Mar 2020 15:49:26 +0000
E, d MMM yyyy HH:mm:ss Z

The following table’s sample column are mostly based on the time December 14th, 2008 4:35 PM UTC.

Characters Example Description
y 2008 Year, no padding
yy 08 Year, two digits (padding with a zero if necessary)
yyyy 2008 Year, minimum of four digits (padding with zeros if necessary)
Q 4 The quarter of the year. Use QQ if you want zero padding.
QQQ Q4 Quarter including "Q"
QQQQ 4th quarter Quarter spelled out
M 12 The numeric month of the year. A single M will use '1' for January.
MM 12 The numeric month of the year. A double M will use '01' for January.
MMM Dec The shorthand name of the month
MMMM December Full name of the month
MMMMM D Narrow name of the month
d 14 The day of the month. A single d will use 1 for January 1st.
dd 14 The day of the month. A double d will use 01 for January 1st.
F 3rd Tuesday in December The day of week in the month
E Tue The abbreviation for the day of the week
EEEE Tuesday The wide name of the day of the week
EEEEE T The narrow day of week
EEEEEE Tu The short day of week
h 4 The 12-hour hour.
hh 04 The 12-hour hour padding with a zero if there is only 1 digit
H 16 The 24-hour hour.
HH 16 The 24-hour hour padding with a zero if there is only 1 digit.
a PM AM / PM for 12-hour time formats
m 35 The minute, with no padding for zeroes.
mm 35 The minute with zero padding.
s 8 The seconds, with no padding for zeroes.
ss 08 The seconds with zero padding.
SSS 1234 The milliseconds.
Time Zone
zzz CST The 3 letter name of the time zone. Falls back to GMT-08:00 (hour offset) if the name is not known.
zzzz Central Standard Time The expanded time zone name, falls back to GMT-08:00 (hour offset) if name is not known.
ZZZZ CST-06:00 Time zone with abbreviation and offset
Z -0600 RFC 822 GMT format. Can also match a literal Z for Zulu (UTC) time.
ZZZZZ -06:00 ISO 8601 time zone format
For the full reference of available format options, see Unicode Technical Reference #35.

About this Site

nsdateformatter.com is written with Swift 4.2, as a means to learn open-source Swift, the Swift Package Manager, and deploying to Linux. It uses the Vapor web application framework and deployed is to Heroku.

The site is open source, so if you want to fix a bug or submit an enhancement, feel free to submit a pull request.

About the Author

Ben Scheirman is a developer from Houston, TX. He is the founder of NSScreencast, where you can find over 350 screencasts on iOS development topics.

You can find Ben on Twitter or his blog.

Want to see how to use DateFormatter in Swift?

Check out this free screencast:

Parsing and Formatting Dates