Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDateFormatter for rails 4.0 created_at

Im trying to parse the created_at that rails returns, it looks like the following.

2013-09-08T09:18:45.500Z

Currently using

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]

This doesn't work, the NSDate returns as nil.

Not sure how i should format after the last dot, hope i can get some help here!

Thanks

like image 422
Ludvig Avatar asked Sep 08 '13 10:09

Ludvig


1 Answers

Capital "S" is for fractional seconds:

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"]

You can find that (and much more!) in "Appendix F: Date Format Patterns" of the "Unicode Technical Standard #35: UNICODE LOCALE DATA MARKUP LANGUAGE".

like image 63
Martin R Avatar answered Oct 21 '22 21:10

Martin R