OC 判断时间戳距离现在是否大于N小时

//判断时间戳(time)距离现在是否大于(specifiedTime)小时

- (BOOL)compareTime:(NSString *)time greaterThanSpecifiedTime:(CGFloat)specifiedTime

{

    //MicrosecondsTimeStamp为当前时间,毫秒级

    NSTimeInterval balance = MicrosecondsTimeStamp/1000 - [time longLongValue]/1000;

    

    NSString*timeString = [[NSString alloc]init];

    

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

    //相差的时间

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

    

    NSInteger timeInt = [timeString intValue];

    

    NSInteger hour = timeInt /60;

    

    NSInteger mint = timeInt %60;

    

    if (hour > specifiedTime) {

        return YES;

    }else if (hour == specifiedTime && mint > 0) {

        return YES;

    }else

        return NO;

}

猜你喜欢

转载自blog.csdn.net/niumanxx/article/details/81745448