标签:
1.
NSTimeInterval 时间间隔double
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; //2001/1/1时间以秒数的形式表示 NSLog(@"double=%f",now);//444907472.111701 // NSDate *datec = [NSDate dateWithTimeIntervalSinceNow:100]; NSTimeInterval seconds = [datec timeIntervalSinceNow]; //日期于当前日期的相差时间 NSLog(@"%f",seconds);//以秒数的形式 // NSDate *datea = [NSDate dateWithTimeIntervalSince1970:0]; NSDate *dateb = [NSDate dateWithTimeInterval:50 sinceDate:datea]; NSTimeInterval secondsa = [datea timeIntervalSinceDate:dateb];//日期与日期的相差时间 NSLog(@"%f",secondsa); /////////////////////////////////////////////////////NSDate的创建///////////////////////////////////////////////////////////////////////////// NSDate *date = [NSDate date]; NSLog(@"date=%@",date); //以当前时间为基准 NSDate *timeInterval = [[NSDate alloc]initWithTimeIntervalSinceNow:20]; NSLog(@"timeInterval= %@",timeInterval); //以1970/1/1为基准 NSDate *since1970= [[NSDate alloc]initWithTimeIntervalSince1970:-20]; NSLog(@"since1970=%@",since1970); //以2001/1/1为基准 NSDate *sinceReferenceDate = [[NSDate alloc]initWithTimeIntervalSinceReferenceDate:80]; NSLog(@"sinceReferenceDate=%@",sinceReferenceDate); //以某日期为基准 NSDate *date2 = [[NSDate alloc]initWithTimeInterval:10 sinceDate:date]; NSLog(@"date2=%@",date2); // NSLog(@"future date = %@",[NSDate distantFuture]); NSLog(@"past date = %@",[NSDate distantPast]);
。
2015-02-06 17:49:38.290 MeiTeamDemo[13580:203531] double=444908978.290587 2015-02-06 17:49:38.291 MeiTeamDemo[13580:203531] 99.999974 2015-02-06 17:49:38.291 MeiTeamDemo[13580:203531] -50.000000 2015-02-06 17:49:38.292 MeiTeamDemo[13580:203531] date=2015-02-06 09:49:38 +0000 2015-02-06 17:49:38.293 MeiTeamDemo[13580:203531] timeInterval= 2015-02-06 09:49:58 +0000 2015-02-06 17:49:38.293 MeiTeamDemo[13580:203531] since1970=1969-12-31 23:59:40 +0000 2015-02-06 17:49:38.293 MeiTeamDemo[13580:203531] sinceReferenceDate=2001-01-01 00:01:20 +0000 2015-02-06 17:49:38.293 MeiTeamDemo[13580:203531] date2=2015-02-06 09:49:48 +0000 2015-02-06 17:49:38.293 MeiTeamDemo[13580:203531] future date = 4001-01-01 00:00:00 +0000 2015-02-06 17:49:38.293 MeiTeamDemo[13580:203531] past date = 0000-12-30 00:00:00 +0000
。
2.统计时间耗时利器
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); // do something CFAbsoluteTime end = CFAbsoluteTimeGetCurrent(); NSLog(@"time cost: %0.3f", end - start);
3.
NSTimeInterval interval = [_startDate timeIntervalSinceNow];//日期相差的秒数 NSString *title = [NSString stringWithFormat:@"做题进度:%ld/%ld 道 剩余时间:%d:%d",_indexOfQuestion + 1, self.dataSource.count ,(int)interval/60,(int)interval%60 ];
标签:
原文地址:http://www.cnblogs.com/huen/p/4277762.html