I have the following string: 20180207T124600Z
How can I turn this into a Date object?
Here is my current code but it returns nil
:<
You need to specify the format options for the ISO8601DateFormatter
to match your requirements (year, month, day and time), here is an example below:
//: Playground - noun: a place where people can play
import UIKit
let dateString = "20180207T124600Z"
let dateFormatter = ISO8601DateFormatter()
dateFormatter.formatOptions = [
.withYear,
.withMonth,
.withDay,
.withTime
]
print(dateFormatter.string(from: Date()))
print(dateFormatter.date(from: dateString))