我需要的最终结果是我想知道多久之前发布了一条评论。为此,我开始执行以下操作:
double timestampComment = [[testArray objectForKey:@"timestamp"] doubleValue]/1000;
NSDate *date = [NSDate date];
NSLog(@"Date: %@", date);
NSTimeInterval timestamp = (NSTimeInterval)timestampComment;
NSDate *actualTime = [NSDate dateWithTimeInterval:timestamp sinceDate:date];
但这不起作用并返回了类似 5213 个月前的内容(它仅在上周发布!)然后我进行了一些搜索,发现时间戳的双精度值,即 1377775454768 实际上是 1377775454768.000000,所以这就解释了为什么时机太不对了。
我现在已经尝试完成一些控制台日志记录,但仍然无法获得 NSTimeInterval 没有十进制值的双精度值。这是我现在尝试过的:
double timer = [[testArray objectForKey:@"timestamp"]doubleValue];
//NSString *timerStr = [NSString stringWithFormat:@"%.0f", timer];
NSString *timerCount = [testArray objectForKey:@"timestamp"];
NSTimeInterval timeIntervalComment = timer;
//NSTimeInterval timeIntervalCount = timerCount;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeIntervalComment];
NSLog(@"Timer: %@", timerCount);
NSString *rightTimestr = [NSString stringWithFormat:@"%.0f", timeIntervalComment];
int timerTest = [rightTimestr intValue];
NSTimeInterval timeTest = (NSTimeInterval)[timerCount doubleValue];
NSDate *testDate = [NSDate dateWithTimeIntervalSince1970:timeTest];
NSLog(@"rightTimestr %@", rightTimestr);
NSLog(@"timerTest %d", timerTest);
NSLog(@"%f", [timerCount doubleValue]);
NSLog(@"Test Date: %@", testDate);
NSLog(@"Timer 2: %f", timer);
NSLog(@"date: %@", date);
这是日志记录的结果:
Timer: 1377775454768
rightTimestr 1377775454768
timerTest 2147483647
1377775454768.000000
Test Date: 45629-12-19 04:06:08 +0000
Timer 2: 1377775454768.000000
date: 45629-12-19 04:06:08 +0000
任何帮助,将不胜感激。谢谢