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
  • 314,917
  • 42
  • 532
  • 579
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263

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
  • 82,064
  • 23
  • 174
  • 143