1

I am sorry to ask this question but i can't find the answer. I try to parse the following String from a server into a NSDate: "2016-03-02 23:20:40.000 +0000"

        let dateFormatter = NSDateFormatter()

        let myDate = "2016-03-02 23:20:40.000 +0000"
        dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss.SSS Z"

        print(dateFormatter.dateFromString(myDate)) //-> nil

I found tons of informations about the dateFormat, but nothing helped me out. I also tried different locals, but it was not successfully. :(

Thanks!!!

TBockmair
  • 83
  • 6
  • 1
    Hint: look at the docs for date format specifiers and see what `hh` is to be used for and then see what format the hour is in your date string. – rmaddy Mar 02 '16 at 22:29
  • Use `HH:mm:ss` as shown here: [NSNumber of seconds to Hours, minutes, seconds](http://stackoverflow.com/questions/1528822/nsnumber-of-seconds-to-hours-minutes-seconds) – JAL Mar 02 '16 at 22:30
  • A better duplicate might be http://stackoverflow.com/questions/25657123/swift-nsdateformatter-not-working since it covers the OP using `hh` instead of `HH`. – rmaddy Mar 02 '16 at 22:37

0 Answers0