0

How would I convert this specific date in String, "2016-06-29T23:00:00-07:00", to an NSDate.

Currently I am looking at this website (http://waracle.net/iphone-nsdateformatter-date-formatting-table/) at the NSDate Formatting Table but I still can't convert the string to an NSDate successfully.

Mtoklitz113
  • 3,828
  • 3
  • 21
  • 40
Stefan DeClerck
  • 1,162
  • 2
  • 12
  • 22

1 Answers1

2

You can do something like this:

let yourDate = "2016-06-29T23:00:00-07:00" //Your date in string.
let dates = NSDateFormatter()
dates.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
if let someVar = dates.dateFromString(yourDate){
print(someVar) //to avoid optional date.
}
Mtoklitz113
  • 3,828
  • 3
  • 21
  • 40
  • Additionally, if you are developing for iOS 10, you can use the new [`NSISO8601DateFormatter`](https://developer.apple.com/reference/foundation/nsiso8601dateformatter) to encode and decode this. – Bringo Jun 29 '16 at 00:30