Search code examples
iosnsdateformatter

Dateformat of 2017-12-16T07:28:59.629Z


What date format I need to process this string? 2017-12-16T07:28:59.629Z

Tried yyyy-MM-dd'T'HH:mm:ssZZZZZ and Tried yyyy-MM-dd'T'HH:mm:sssZZZZZ

Anyway how many s and Z needs end of the format?

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:sssZZZZZ"
date = dateFormatter.date(from: value as! String)

Solution

  • use the dateformat as

    dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
    

    as the Date Format Patterns suggests that "S" is the format specifier for fractions of seconds.