Formatted Date strings in Swift and SwiftUI

preview_player
Показать описание
In this video we are going to explore Swift Dates and how you can format dates as strings for presentation in your Swift / SwiftUI projects.
We will look at the DateFormatter class and it's dateStyle and timeStyle properties.
This will be followed by using fixed format date representations using a format string.
In iOS 14 with SwiftUI we got an easier way to display dates In text views so we will explore the formatter initializer that was introduced.

If you want to support my work, you can buy me a coffee :)

Table of Contents:
0:00 Introduction
1:33 Date Formatter - DateStyle and TimeStyle
7:48 Date Formatter Fixed Format Date Representation
15:49 iOS 14 - SwiftUI Text view formatter and format options
2248 iOS 15 - SwiftUI Text View style option

Starter Project Files:
(If you are having problems downloading zip files, use Safari. Chrome restricts zip files by default)

Completed Project:

Other References:
Stewart Lynch's YouTube Channel:
Stewart Lynch on Mastodon:
Stewart Lynch on Twitter:
Stewart Lynch on LinkedIn
Рекомендации по теме
Комментарии
Автор

The ones that return locale-aware strings are my favourite because they update automatically if the region settings are changed

indiekiduk
Автор

Thank you, Stewart. Learned something new. The date representation in Text().
I struggled a while to figure out how to derive the locale of the user’s device in order to display the date correctly. Not sure whether that was necessary or not.

mhfs
Автор

Thanks Stewart, really practical and complete.

DatafoxSoftware
Автор

Thanks! Fantastic explanation! Makes it really clear now!

martinhandl
Автор

Thank you very much, Stewart. You make it very clear and easy. This is the topic that I have always been scared off but not any more. Thank you again for all the great works.

TuanHoang-qjyq
Автор

Such a complicated subject but you make it very clear and easy to understand - Thanks 😊

trevormills
Автор

3:31 for me, the time was not displayed in the style of my system (Austria). 🤷‍♂

michaelschafferAT
Автор

Awesome! I always learn something new from your videos. Thank you so much!

andresraigoza
Автор

Great video which will avoid many a headache 🙂

larschristiansen
Автор

What is the difference between using Date() rather than Date.now()? As I have used Date() in other languages, I use it by default and it gives me the right output but am I missing something by not using the .now?

kenturnbull
Автор

Hello, may I ask what screen recording software you are using?

wendstation
Автор

The "ah-HA!" moments came from how you broke out iOS 14, and iOS 15 updates. It's great to see how Apple continues to improve ease-of-development. Your breakdown adds tremendous clarity.

However, -5 points for "ContentView". 👎

obelix
visit shbcf.ru