美文网首页
iOS 开发技巧 - 计算两个时间的差值

iOS 开发技巧 - 计算两个时间的差值

作者: 程序猿李墨 | 来源:发表于2018-06-20 16:42 被阅读0次

/**

* @method

*

* @brief 获取两个日期之间的天数

* @param fromDate      起始日期

* @param toDate        终止日期

* @return    总天数

*/

+ (NSInteger)numberOfDaysWithFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate{

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

    NSDateComponents    * comp = [calendar components:NSCalendarUnitDay

                                            fromDate:fromDate

                                              toDate:toDate

                                              options:NSCalendarWrapComponents];

    NSLog(@" -- >>  comp : %@  << --",comp);

    return comp.day;

}

iOS 计算两个日期之间的天数问题

相关文章

网友评论

      本文标题:iOS 开发技巧 - 计算两个时间的差值

      本文链接:https://www.haomeiwen.com/subject/fkuxyftx.html