iOS如何将日期字符串转成NSDate
没事玩新浪微博, 可取得日期字符串"Wed May 2 22:27:08 +0800 2012", 想做日期计算,想转成NSDate,根据网上资料,可先设置对应的NSDateFormatter,然后再从其转成对应的NSDate, 对应的代码片段如下:
NSString* dateStr = @"Wed May 2 22:27:08 +0800 2012";
NSDateFormatter* formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"EEE MMM d HH:mm:ss zzzz yyyy"];
NSDate* date = [formater dateFromString:dateStr];
NSLog(@"%@", date);
//NSDate* now = [NSDate now];
double inter = fabs([date timeIntervalSinceNow]);
if( inter < 60)
NSLog(@"1 mins ago!");
else if(inter < 60*60)
NSLog(@"1 hours ago!");
else if(inter < 60*60*24)
NSLog(@"1 days ago!");
NSLog(@"interval is %f min", inter/60);
摘自 keyken的专栏
补充:移动开发 , 其他 ,