swift - Why is my NSDateFormatter returning nil? -


this question has answer here:

lastreviewdate = "2016-06-06t20:24:15.9313557z"

var formatter = nsdateformatter()     formatter.dateformat = "yyyy-mm-ddthh:mm:ss.ssssssz"     let date = formatter.datefromstring(lastreviewdate) 

date returns nil. why happening, looks format matches string exactly.

"hh" used or pm, if want use 0-23 hour , have use "hh" or want 1-24 hour use "kk"

use dateformat string work

"yyyy-mm-dd't'hh:mm:ss.ssssss'z'"

check document

https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsdateformatter_class/index.html