0

I have a String is this format:

2017-10-09 13:28:36 +0000
"M/dd/yyyy hh:mm:ss a"

I would like to present dates like so:

Mon Oct 9th
"EEEE, MMM d, h:mm a"

Should I just Calendar Components to construct the date or is there a way to use DateFormatter?

I currently download JSON that contains User "Checkins" and the time they checkedin:

if let dateTime = dict["dateTime"] as? String {
   let dateFormatter = DateFormatter()
   dateFormatter.dateFormat = "M/dd/yyyy hh:mm:ss a"
   dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
   let myDate =  dateFormatter.date(from: dateTime)!
   print(myDate) // 2017-10-09 13:28:36 +0000
   // dateFormatter.dateFormat = "EEEE, MMM d, h:mm a" Desired Date Format

   checkinObject.dateTime = myDate

}

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55
  • 1
    `DateFormatter` does not support ordinal days like 9th. By the way: The input format does not match the string at all. The matching format is `yyyy-MM-dd HH:mm:ss Z` – vadian Oct 09 '17 at 17:35
  • check answers here https://stackoverflow.com/questions/3917250/converting-nsstring-to-nsdate-and-back-again – Abdoelrhman Oct 09 '17 at 17:47

0 Answers0