1

Here is my code to convert but I had a nil value. Any help is appreciated

 func serverToLocal(date:String) -> Date? {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
        dateFormatter.timeZone = TimeZone(abbreviation: "GTM")
        let localDate = dateFormatter.date(from: date)

        return localDate
    }

And he is my call:

let res = self.serverToLocal(date: "2015-06-18T17:02:02.614Z")
Fabio
  • 1,913
  • 5
  • 29
  • 53
  • Your date format lacks the fractional seconds and the time zone (the `.614Z` part). The date formatter considers the local time zone by default. – vadian Aug 12 '20 at 16:53
  • What is GTM? kkkk – Leo Dabus Aug 12 '20 at 17:17
  • 1
    https://stackoverflow.com/questions/28016578/how-to-create-a-date-time-stamp-and-format-as-iso-8601-rfc-3339-utc-time-zone/28016692#28016692 – Leo Dabus Aug 12 '20 at 17:19

0 Answers0