Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

iOS-Swift How to convert a String of Date to another String of Date

I have this String "Aug 15, 2022". How can I convert it to "Monday, August 15, 2022"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//First u have to convert ur date to a Date object
let dateFormatterGet = DateFormatter()
dateFormatterGet.dateFormat = "MM dd, yy"
dateFormatterGet.locale = Locale(identifier: "en_US_POSIX")
let date = dateFormatterGet.date(from: "Aug 15, 2022")

//Next crate a formatter that gives u the desired output
let dateFormatterSet = DateFormatter()
//EEEE -> for the day name -> in your case Monday
//MMMM -> for the full month name (if u use MM it will give u 'Aug`)
dateFormatterSet.dateFormat = "EEEE, MMMM dd, yyyy"
let updatedDate = dateFormatterSet.string(from: date!)

print(updatedDate) // -> Monday, August 15, 2022
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading