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?
views:
179answers:
2
+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
2010-02-02 04:26:58
+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
2010-02-02 04:31:53
I get this warning with your code:"no '-initWithDateFormat:allowNaturalLanguage:' method found"Any ideas?
Amagrammer
2010-02-24 17:10:03
Looks like that's Mac OS only, not iPhone. Never mind.
Amagrammer
2010-02-24 17:32:00