美文网首页
iOS 计算两个NSDate间间隔天数

iOS 计算两个NSDate间间隔天数

作者: MMOTE | 来源:发表于2017-05-16 09:50 被阅读0次

    +(NSInteger)getDaysFrom:(NSDate *)serverDate To:(NSDate *)endDate
    {
    NSCalendar *gregorian = [[NSCalendar alloc]
    initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

    [gregorian setFirstWeekday:2];
    

    //去掉时分秒信息
    NSDate *fromDate;
    NSDate *toDate;
    [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&fromDate interval:NULL forDate:serverDate];
    [gregorian rangeOfUnit:NSCalendarUnitDay startDate:&toDate interval:NULL forDate:endDate];
    NSDateComponents *dayComponents = [gregorian components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0];

    return dayComponents.day;
    

    }

    相关文章

      网友评论

          本文标题:iOS 计算两个NSDate间间隔天数

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