Working with Dates in Swift
It’s inevitable that at some point in your development career you’ll need to work with dates. Maybe you’re showing a feed of posts à la Facebook, or the upcoming schedule of your favorite sports team. While dates are easy conceptually, they aren’t so easy when you’re writing code for formatting and displaying them.
The Date Struct
Today’s Date
Getting today’s date, or more accurately the date and time right now, couldn’t be simpler. All you need to do is create an instance of the Date struct and you’re good to go!
A Future Date
You don’t always want to work with today’s date though. Sometimes you need a Date struct that represents tomorrow, or even a few days later. For that, there are a couple of handy convenience initializers on the Date struct.
DateFormatter
OK, so now that we know how to create Dates we need to figure out how to display them. That’s where the DateFormatter class comes in.
So What’s a DateFormatter?
Everything you need to grow your business
Crafting exceptional mobile experiences so you stand out in a crowded digital landscape. Trusted by Experian, Vrbo, & Expedia.
Let's do it together