How to generate a date time stamp, using the format standards for ISO 8601 and RFC 3339?
The goal is a string that looks like this:
\"2015-01-01T00:0
If you're targeting iOS 11.0+ / macOS 10.13+, you simply use ISO8601DateFormatter
with the withInternetDateTime
and withFractionalSeconds
options, like so:
let date = Date()
let iso8601DateFormatter = ISO8601DateFormatter()
iso8601DateFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let string = iso8601DateFormatter.string(from: date)
// string looks like "2020-03-04T21:39:02.112Z"