-1

How to convert "2018-04-03 22:10:06" to "Tue Apr 3 22:10:06 2018"? Obviously not those specific dates but that format.

I found this solution:

How to convert date format from dd/MM/YYYY to YYYY-MM-dd in swift

but I am unable to get it to the exact format.

gooberboobbutt
  • 797
  • 2
  • 8
  • 19

1 Answers1

0

So, I just threw this into Playgrounds

let inFormat = DateFormatter()
inFormat.dateFormat = "yyyy-MM-dd HH:mm:ss"

let date = inFormat.date(from: "2018-04-03 22:10:06")

let outFormat = DateFormatter()
outFormat.dateFormat = "E MMM d HH:mm:ss yyyy"
outFormat.string(from: date!)

It eventually outputs Tue Apr 3 22:10:06 2018

The formats were initial referenced from nsdateformatter.com

This, of course, will use the current system TimeZone and Locale, so you may want to do some more investigation into that

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366