开发者

How do I get a timestamp from an NSString date?

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开发者_StackOverflow中文版. How can I change the NSString date into a timestamp value?


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"];


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:].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜