0

I have a string which is coming from an API that I need to convert into a NSDate but I'm uncertain which dateFormat to use for NSDateFormatter.

let openedAt = "2015-06-30T12:34:00.000-04:00" // coming from API

let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd..." // not sure what format to use here

if let date = formatter.dateFromString(openedAt) {
    println(date)
} else {
    println("NOPE!")
}
rmaddy
  • 307,833
  • 40
  • 508
  • 550
Kyle Decot
  • 19,788
  • 38
  • 138
  • 255

1 Answers1

2

try

 "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"

The Date Format Patterns guide suggests that "S" is the format specifier for fractions of seconds.

Anbu.Karthik
  • 80,161
  • 21
  • 166
  • 138