简单的就是说 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);
}
(void)viewWillDisappear:(BOOL)animated { NSDateFormatter *date=[[NSDateFormatter alloc] init]; [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *currentEndTime = [date stringFromDate:[NSDate date]]; NSCalendar *cal=[NSCalendar currentCalendar]; unsigned int unitFlags= NSYearCalendarUnit| NSMonthCalendarUnit| NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit; NSDateComponents *d = [cal components:unitFlags fromDate:self.currentTime toDate:currentEndTime options:0]; NSLog(@"%d天%d小时%d分钟%d秒",[d day],[d hour],[d minute],[d second]);
}
打印
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)GetStringTimeDiff:(NSString*)timeS timeE:(NSString*)timeE
{
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;
}
(NSString*)GetCurTime
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSString*timeString=[formatter stringFromDate: [NSDate date]];
[formatter release];
return timeString;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。