0

in swift 2.x I used toDate function to get iso date using SwiftDate. Any one knows the right replacement for this:

let isoDate = stringDate.toDate(DateFormat.ISO8601Format(.Extended))

Looking at the SwiftDate documentations, I've tried something like this:

let isoDate = stringDate.date(format:.iso8601)

but it complaints about format

EDIT:

I changed SwiftDate version from 4.0.7 to 4.0.3 and now iso format exists but throws an error

my date string: "2016-11-24T03:00:00.000Z"

let isoDate = try! dt.date(format: DateFormat.iso8601(options: .extended)).absoluteDate

error: Type 'ISO8601DateTimeFormatter.Options' has no member 'extended'

let isoDate = try! dt.date(format: DateFormat.iso8601(options: [])).absoluteDate

error: no error but throws

in swift 2.2 I used exactly the same date format.

Maciej Chrzastek
  • 1,380
  • 12
  • 18

1 Answers1

0

According to the SwiftDate CHANGELOG:

SwiftDate 4.0.5

  • #293 Added .withInternetDateTimeExtended as options of ISO8601DateTimeFormatter

And here is the source file:

// The format used for internet date times; it's similar to .withInternetDateTime
// but include milliseconds ('yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ').
public static let withInternetDateTimeExtended = ISO8601DateTimeFormatter.Options(rawValue: 1 << 11)

This compiles on the current latest version (SwiftDate 4.0.7):

let stringDate = "2016-11-24T03:00:00.000Z"
let options = ISO8601DateTimeFormatter.Options.withInternetDateTimeExtended
let format = DateFormat.iso8601(options: options)
let isoDate = try? stringDate.date(format: format)
buildc0de
  • 193
  • 5
  • unfortunately, there is no extended option: Type 'ISO8601DateTimeFormatter.Options' has no member 'Extended'. I changed withInternetDateTimeExtended to withInternetDateTime but it creates nil instead of date. I think that extended part is the key. Perhaps it is a framework version issue? On which version did you check? – Maciej Chrzastek Nov 24 '16 at 09:49
  • annnd that's the solution :) I was using 4.0.3 :( – Maciej Chrzastek Nov 24 '16 at 12:47