objective-c计算相对于现在的时间差
最近做了一个小应用程序,是读取新浪微博的。微博上面对于新发的微博,不是告诉你具体什么时候发布的,而是告诉你几秒钟之前,几分钟之前,几个小时之前之类的相对于现在的时间。可以使用下面代码来计算这个时间差。 - (NSString * )timestamp { // Calculate distance time string // time_t now; time( & now); int distance = ( int )difftime(now, createdAt); if (distance < 0 ) distance = 0 ; if (distance < 60 ) { self.timestamp = [NSString stringWithFormat: @" %d %s " , distance, (distance == 1 ) ? " second ago " : " seconds ago " ]; } else if (distance < 60 * 60 ) { distance = distance / 60 ; self.tim...