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.
+2
A:
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
2009-08-28 20:07:27
Didn't even think about a Formatter, since that sounds like something that prints out something nice. But good to know!
HelloMoon
2009-08-28 21:51:22