美文网首页
IOS 判断两个时间相隔多少天

IOS 判断两个时间相隔多少天

作者: kaka0203x | 来源:发表于2016-10-19 15:50 被阅读0次

    - (NSString *)intervalFromLastDate: (NSString *) dateString1toTheDate:(NSString *) dateString2

    {

    NSDateFormatter *date=[[NSDateFormatter alloc] init];

    [date setDateFormat:@"yyyy-MM-dd"];

    NSDate *d1=[date dateFromString:dateString1];

    NSTimeInterval late1=[d1 timeIntervalSince1970]*1;

    NSDate *d2=[date dateFromString:dateString2];

    NSTimeInterval late2=[d2 timeIntervalSince1970]*1;

    NSTimeInterval cha=late2-late1;

    NSString *timeString=@"";

    NSString *house=@"";

    NSString *min=@"";

    NSString *sen=@"";

    sen = [NSString stringWithFormat:@"%d", (int)cha%60];

    sen=[NSString stringWithFormat:@"%@", sen];

    min = [NSString stringWithFormat:@"%d", (int)cha/60%60];

    min=[NSString stringWithFormat:@"%@", min];

    house = [NSString stringWithFormat:@"%d", (int)cha/3600];

    house=[NSString stringWithFormat:@"%@", house];

    timeString=[NSString stringWithFormat:@"差小时:%@-----分:%@------秒:%@",house,min,sen];

    return timeString;

    }

    相关文章

      网友评论

          本文标题:IOS 判断两个时间相隔多少天

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