美文网首页
iOS计算两个时间戳的时间差

iOS计算两个时间戳的时间差

作者: JasonEVA | 来源:发表于2016-03-07 10:54 被阅读5530次

    ```

    //计算两个时间戳的时间差

    + (NSString*)compareTwoTime:(longlong)time1 time2:(longlong)time2

    {

    NSTimeIntervalbalance = time2 /1000- time1 /1000;

    NSString*timeString = [[NSStringalloc]init];

    timeString = [NSStringstringWithFormat:@"%f",balance /60];

    timeString = [timeStringsubstringToIndex:timeString.length-7];

    NSIntegertimeInt = [timeStringintValue];

    NSIntegerhour = timeInt /60;

    NSIntegermint = timeInt %60;

    if(hour ==0) {

    timeString = [NSStringstringWithFormat:@"%ld分钟",(long)mint];

    }

    else

    {

    if(mint ==0) {

    timeString = [NSStringstringWithFormat:@"%ld小时",(long)hour];

    }

    else

    {

    timeString = [NSStringstringWithFormat:@"%ld小时%ld分钟",(long)hour,(long)mint];

    }

    }

    returntimeString;

    }

    @end

    ```

    相关文章

      网友评论

          本文标题:iOS计算两个时间戳的时间差

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