Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
Hello.
i have date as string "Sat, 29 Nov 2008 00:00:00 -0500"
and i'm trying to create NSDate from it with this code
Code:
[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"%a, %d %b %Y %H:%M:%S %Z"];
NSDate *date = [dateFormatter dateFromString:@"Sat, 29 Nov 2008 00:00:00 -0500"];

Date is always nil.

Can someone help me with this?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
You're starting by defining dateFormatter like so:
Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
correct?

I tried the following code block and date was not nil:
Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"];
NSDate *date = [dateFormatter dateFromString:@"Sat, 29 Nov 2008 00:00:00 -0500"];
 

pashik

macrumors member
Original poster
Jul 16, 2008
43
0
You're starting by defining dateFormatter like so:
Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
correct?

I tried the following code block and date was not nil:
Code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"];
NSDate *date = [dateFormatter dateFromString:@"Sat, 29 Nov 2008 00:00:00 -0500"];

It looks like after installing sdk 2.2 date is not nil any more even if i set target sdk to 2.0.

thank you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.