views:

576

answers:

4

Seems like a simple thing but I can't seem to find a way to do it.

It would be great to see a couple different methods.

Thanks,

Nick

A: 

Use [NSDate dateWithString:@"YYYY-MM-DD HH:MM:SS ±HHMM"], where +-HHMM is the timezone offset. There is a very good reference of NSDate over at Mac Dev Center ;)

l_simon_l
A: 

NSDate class has two

dateWithString

initWithString

Codezy
+1  A: 

See the documentation for NSDate. You can use the dateFromString: method of NSDateFormatter or the dateFromComponents: method of NSCalendar.

zoul
I keep getting this date : "1969-12-31 16:00:00" -0800 when using date from string
nickthedude
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDate *capturedStartDate = [dateFormatter dateFromString: @"Jan 2, 2001"]; NSLog(@"%@", [capturedStartDate description]);output: 2010-04-05 10:49:47.688 Calendar2[21339:207] 1969-12-31 16:00:00 -0800
nickthedude
Maybe you need to set some parameters on the date formatted instead of plain `init`?
zoul
+1  A: 

If you're talking about a specific calendar date rather than a UNIXy date, you probably want NSCalendar's dateFromComponents:.

Chuck