ISO8601DateFormatter doesn't parse ISO date string

I’m trying to parse this


  • Alternative to ffmpeg for iOS
  • how to convert gps north and gps west to lat/long in objective c
  • .app file not found in Derived Data
  • Getting row of UITableView cell on button press
  • ios plugin do not show provided text
  • Debug ipad safari with a PC
  • using native ISO8601DateFormatter class provided by iOS 10 but always fails.
    If the string not contains milliseconds, the Date object is created without problems.

    I’m tried this and many options combination but always fails…

    let formatter = ISO8601DateFormatter()
    formatter.timeZone = TimeZone(secondsFromGMT: 0)
    formatter.formatOptions = [.withInternetDateTime, .withDashSeparatorInDate, .withColonSeparatorInTime, .withColonSeparatorInTimeZone, .withFullTime]

    Any idea?

    Solutions Collect From Internet About “ISO8601DateFormatter doesn't parse ISO date string”

    ISO8601DateFormatter does not support date strings including milliseconds.

    A workaround is to remove the millisecond part with regular expression.

    let isoDateString = "2017-01-23T10:12:31.484Z"
    let trimmedIsoString = isoDateString.replacingOccurrences(of: "\\.\\d+", with: "", options: .regularExpression)
    let formatter = ISO8601DateFormatter()
    let date = trimmedIsoString)

    Edit: In macOS 10.13+ / iOS 11+ a new option is added to support fractional seconds:

    static var withFractionalSeconds: ISO8601DateFormatter.Options { get }