⽇期字符串转换and两个⽇期相减
//创建当前⽇期
NSDate *date = [NSDate date];
//创建⽇期格式类
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
//设置⽇期格式
[dateFormat setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
//获取招聘信息的创建⽇期
NSDate *createDate =[dateFormat dateFromString:_ateTime];
NSLog(@"ateTime==》%@ date==>:%@ - createDate:%@",ateTime,date,createDate);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int unitFlags = NSDayCalendarUnit;
NSDateComponents *comps = [gregorian components:unitFlags fromDate:createDate  toDate:date  options:0];
int days = [comps day];
NSLog(@"天数===%d",days);
打印:
字符串截取日期ateTime==》2014/5/7 14:57:49 date==>:2014-05-15 07:45:34 +0000 - createDate:2014-05-07 06:57:49 +0000

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。