iOS 两日期之间相差几天
作者:
劉光軍_MVP | 来源:发表于
2015-12-01 15:41 被阅读4459次- (NSInteger)getDifferenceByDate:(NSString *)date {
//获得当前时间
NSDate *now = [NSDate date];
//实例化一个NSDateFormatter对象
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//设定时间格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *oldDate = [dateFormatter dateFromString:date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int unitFlags = NSDayCalendarUnit;
NSDateComponents *comps = [gregorian components:unitFlags fromDate:oldDate toDate:now options:0];
return [comps day];
}
本文标题:iOS 两日期之间相差几天
本文链接:https://www.haomeiwen.com/subject/szvjhttx.html
网友评论