Learn Courses My Dashboard

How convert ISO 8601 format to a string normal date?

have this SpaceX API that I have to call but idk how set this date like a normal date and display it on a tableview

Captura de Pantalla 2021-03-25 a la(s) 11.03.57

This looks like it’s from a JSON response to an API call, so the easiest way to do it is something like this:

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601

This will turn the "date_local" string value into a Swift Date when you decode the JSON. You can then use a DateFormatter to display it in whatever format you desire.

1 Like