I need an ISO 8601 date formatter With Milliseconds and Timezone in Swift.
Here's a sample date object:
'2017-06-03T01:04:17.826050+00:00'
The documentations seem to require a date with the following format: YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM
, which is ISO 8601 if I'm correct.
But attempting to create a DateFormatter with that format doesn't seem to work:
var dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM"
dateFormatter.string(from: Date())
Which outputs 2017-06-154
, which is not the expected format.
The standard ISODateFormatter()
also does not output the expected format.