Extensions to convert Date to String
Nowadays the extensions are so powerful, they make your life so much easier and your code cleaner.
Here we have four extensions to convert any Date
to String
, also how to add minutes and days to your date.
Usually, to convert takes a couple of lines. Let’s see how to make it in just one line:
Usage:
let currenTime = Date().currentUTC().convertToString(format: “dd-MM-yyyy”)
let minus5DaysFromNow = Date().currentUTC().add(days: -5).convertToString(format: “dd-MM-yyyy”)
Now let’s see how to convert String to Date
PS: here is the date format, you can grab the format that you need
The extensions are so powerful, they help developers to organise their code write less and clean code. And they’re downright awesome!