我有以下代码:
NSDate *commentPostedDate = [[NSDate alloc] initWithTimeIntervalSince1970:[self.newsFeedStream_.timestamp_ intValue]];
NSLog(@"TIMESTAMP IS %@", self.newsFeedStream_.timestamp_);
int interval = (int) [[NSDate date] timeIntervalSinceDate:commentPostedDate] / 60;
[commentPostedDate release];
NSString *timePosted = [NSString stringWithFormat:@"%d hours ago", interval];
但是,这似乎没有返回正确的小时前。我在这里做错了什么?
最佳答案
UNIX 时间戳通常以秒为单位,那么如果您想要小时,为什么要除以 60?
一小时有 3600 秒,而不是 60 秒。
关于iphone - unix 时间戳到几小时前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456974/