views:

80

answers:

3

Let's say I have something like 30-10-2025 12:53, how could I convert that to an NSDate? I guess there's some class that takes this plus an format string that tells it how the date looks as a string, so it can parse it... where must I look?

A: 

You can use the NSDateFormatter class for this purpose.

Claus Broch
+5  A: 

You can use NSDateFormatter

 NSDateFormatter *k= [[NSDateFormatter alloc] init];
  [k setFormat:@"your string format"] //ex @"MM/DD/yyyy hh:mm:ss" 
 NSDate *d=[k dateFromString:yourString];
 [k release]

Here is a reference DateFormatter ref

Daniel
Mac OS X 10.5 and later, and all versions of iOS, expect format strings according to this specification: http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
Alex
+1  A: 

You can find a few examples here on using NSDateFormatter

Date Formatter Examples Take 1

Date Formatter Examples Take 2

Date Formatter Examples Take 3

John