views:

179

answers:

2

I have an NSString date (@"Mon, 01 Feb 2010 20:25:37 +0000") that I want to change into a timestamp so that I can better calculate how much time has elapsed from the current time. How can I change the NSString date into a timestamp value?

+1  A: 

Use +[NSDate dateWithString:] if the format is "2001-03-24 10:45:32 +0600".

If not, you need to construct an NSDateFormatter, then use -[NSDateFormatter dateFromString:].

KennyTM
+1  A: 

Haven't fully tested this out but it should do the trick.

NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ" allowNaturalLanguage:NO];
NSDate *date = [formatter dateWithString:@"Mon, 01 Feb 2010 20:25:37 +0000"];
Giao
I get this warning with your code:"no '-initWithDateFormat:allowNaturalLanguage:' method found"Any ideas?
Amagrammer
Looks like that's Mac OS only, not iPhone. Never mind.
Amagrammer