簡單的就是說 a = 終止 - 起始
求大神 幫忙解答,
求代碼演示;
我是這樣算的
(void)viewDidAppear:(BOOL)animated
{
NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
self.currentTime = [formatter stringFromDate:[NSDate date]];
NSLog(@"DATE = %@", [NSDate date]);
NSLog(@"ooooo%@", self.currentTime);
}
}
打印
015-04-27 13:47:36.082 H_J_4[30420:576015] -[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7fd6c144ebd0
(lldb)
ios計算時間差 轉
//模擬windows下 GetTickCount //
//#import
(int)mxGetTickCount;
{
int timeTick;
mach_timebase_info_data_t info;
uint64_t machineTime;
mach_timebase_info(&info);
machineTime =mach_absolute_time();
timeTick = machineTime * info.numer / info.denom /1000000LL;
return timeTick;
}
// NSDate timeIntervalSinceDate:
//下面轉換NSString,用在保存時間時使用。
{
double timeDiff = 0.0;
NSDateFormatter *formatters = [[NSDateFormatter alloc] init];
[formatters setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSDate *dateS = [formatters dateFromString:timeS];
NSDateFormatter *formatterE = [[NSDateFormatter alloc] init];
[formatterE setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSDate *dateE = [formatterE dateFromString:timeE];
timeDiff = [dateE timeIntervalSinceDate:dateS ];
return timeDiff;
}
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSString*timeString=[formatter stringFromDate: [NSDate date]];
[formatter release];
return timeString;
}