I have strings with dates, and want to parse these into NSDate objects. Is there a way to do that? I've looked at NSDate and NSScanner, and haven't seen anything that would read it in from a string.
Asked
Active
Viewed 422 times
2 Answers
2
In the cocoa sdk, it's usually: If you want a date and have a string, look in the "Date" class for a create method that accepts a string.
[NSDateFormatter dateFromString:myString]
dateFromString:
Returns a date representation of a given string interpreted using the receiver’s current settings.
(NSDate *)dateFromString:(NSString *)string
So if you want a string and have a date, you look for an NSString Static function called stringFromDate (i'm guessing it exists but didn't look it up). I will concede that NSDateFormatter doesn't strike me as the first place i'd look for this function though.

Brett Bender
- 19,388
- 2
- 38
- 46
-
Didn't even think about a Formatter, since that sounds like something that prints out something nice. But good to know! – Aug 28 '09 at 21:51