I have the following string: 20180207T124600Z
How can I turn this into a Date object?
Here is my current code but it returns nil:<
ISO8601DateFormatter should be something like
yyyy-MM-dd'T'HH:mm:ssZ
as long as your date string is in right format, it won't return nil.
as for formatOptions, it's Options for generating and parsing ISO 8601 date representations according Apple docs
Swift 4
in your example, it should be something like this:
let dateString = "2016-11-01T21:10:56Z"
let dateFormatter = ISO8601DateFormatter()
let date = dateFormatter.date(from: dateString)
let dateFormatter2 = ISO8601DateFormatter()
dateFormatter2.formatOptions = .withFullTime
print(dateFormatter2.string(from: date!))