日期字符串转换 and 两个日期相减

    //创建当前日期
NSDate *date = [NSDate date];
//创建日期格式类
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
//设置日期格式
[dateFormat setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
//获取招聘信息的创建日期
NSDate *createDate =[dateFormat dateFromString:_recruit.createTime]; NSLog(@"recruit.createTime==》%@ date==>:%@ - createDate:%@",recruit.createTime,date,createDate); NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int unitFlags = NSDayCalendarUnit;
NSDateComponents *comps = [gregorian components:unitFlags fromDate:createDate toDate:date options:];
int days = [comps day];
NSLog(@"天数===%d",days);

打印:

recruit.createTime==》2014/5/7 14:57:49 date==>:2014-05-15 07:45:34 +0000 - createDate:2014-05-07 06:57:49 +0000

上一篇:读取XML文件


下一篇:启动php-fpm报错:please specify user and group other than root