如下的代码内容是关于objective c字符串转化成NSDate类型,计算与当前时间的相差,月数,天数的代码。
NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit;
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
NSLog(@"fromdate=%@",fromDate);
[format release];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSLog(@"enddate=%@",localeDate);
NSInteger months = [components month];
NSLog(@"month=%d",months);
NSLog(@"days=%d",days);
[gregorian release];
if (months==0&&days;==0) {
dateStr=[[dateStr substringFromIndex:11]substringToIndex:5];
}else if(months==0&&days;==1){
dateStr=[[dateStr substringFromIndex:11]substringToIndex:5];
}else{
dateStr=[dateStr substringToIndex:10];
cell.textLabel.text=dateStr;
}