根据时间戳来计算倒计时

时间:2020-11-29 17:09:04



 timeLabel =[[UILabelalloc] initWithFrame:CGRectMake(0,objV.frame.size.height-39,iPhoneWidth,39)];

// 创建一个NSTimer类

        [NSTimerscheduledTimerWithTimeInterval:0.01target:selfselector:@selector(timeMethodGo:)userInfo:nilrepeats:YES];


-(void)timeMethodGo:(NSTimer *)timer{

    BOOL timeStart = YES;

    int  totalSeconds=[activityDict[@"end_time"]intValue];

    

    NSDate *datenow = [NSDatedate];

    NSString *timeSp = [NSStringstringWithFormat:@"%ld", (long)[datenowtimeIntervalSince1970]];

    

    int tt=totalSeconds-[timeSp intValue];

    

    

    int d=tt/(3600*24);

    int h=(tt-d*3600*24)/3600;

    int m=(tt-d*3600*24-h*3600)/60;

    int s=tt-d*3600*24-h*3600-m*60;

    

    timeLabel.backgroundColor=[UIColorclearColor];

    timeLabel.textColor=[UIColorgrayColor];

    

    timeLabel.font = [UIFontsystemFontOfSize:15];

    timeLabel.text=[NSStringstringWithFormat:@"距离结束时间 :%d%d%d%d",d,h,m,s];

    timeLabel.textAlignment=NSTextAlignmentCenter;

    [objV addSubview:timeLabel];


}