Swift Tutorial: DateFormatter (dateStyle, Locale, am/pm, dateFormat, weekdaySymbols)

Опубликовано: 21 Февраль 2026
на канале: Swift Goose
1,794
41

In this Swift tutorial we’ll look at how to use DateFormatter to format dates in both a pre-defined way using Swift’s ‘style’ enums, as well as custom formats using dateFormat. We’ll format date, time, weekday symbols, and more.

Days:
E, EE, EEE - Wed
EEEE - Wednesday / or weekday symbol
EEEEE - W

Months:
M - 4
MM - 04
MMM - Apr
MMMM - April
MMMMM - A

Years:
Y - 2021
YY - 21
YYY - 2021
YYYY - 2021

year:
y, yy, yyy, yyyy - 2021

Time Zone:
Z, ZZ, ZZZ - -04:00
ZZZZ - GMT-04:00

Hit the like button, comment, subscribe, and hit the dinner bell to be notified of my next video!

If you'd like to support my work to help me improve video quality and bring more content, please consider donating to my PayPal:
https://www.paypal.com/paypalme/Swift...

00:00 Intro
00:17 Create DateFormatter()
00:28 AM and PM symbols
00:58 dateStyle
01:17 timeStyle
01:43 Locale
02:41 dateFormat
03:44 Days of the week (E)
03:56 weekdaySymbols
05:09 Months (M)
05:25 Years (Y)
05:59 Seconds (s and S)
06:13 Time zone (Z)
07:10 setLocalizedDateFormatFromTemplate
07:30 End

Subscribe for more content, as I will be creating more tutorial and how-to videos for coding in Swift, as well as longer tutorials on building macOS apps.

Thank you for watching!

Huge thank you to the channels below for helping me get started!
Uncreated Light Press
   / @uncreatedlightpress  
and

Mr. Macintosh
   / @mr.macintosh  
and

The Apple Ninja
   / jessetheappleninja