1.获取时间的年,月,日,时,分,秒
1 //"expireDatetime": "2015-07-28 17:29:48.0" <==> 转换 2 NSString *dateStr = [model.expireDatetime substringToIndex:model.expireDatetime.length-cutLength]; 3 //装换成日期 4 NSDateFormatter *df = [[NSDateFormatter alloc]init]; 5 [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 6 NSDate *date = [df dateFromString:dateStr]; 7 //计算时间差 8 //参数1:时间差里包含的内容(年,月,日,时,分,秒) 9 //参数2:起始时间 10 //参数3:结束时间 11 //参数4:比较的一些附加参数 12 NSCalendar *calendar = [NSCalendar currentCalendar]; 13 unsigned int unit = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond; 14 NSDateComponents *dc = [calendar components:unit fromDate:[NSDate date] toDate:date options:0];