根据时间戳来计算倒计时



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

// 创建一个NSTimer类

        [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timeMethodGo:) userInfo:nil repeats:YES];


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

    BOOL timeStart = YES;

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

    

    NSDate *datenow = [NSDate date];

    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];

    

    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=[UIColor clearColor];

    timeLabel.textColor=[UIColor grayColor];

    

    timeLabel.font = [UIFont systemFontOfSize:15];

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

    timeLabel.textAlignment=NSTextAlignmentCenter;

    [objV addSubview:timeLabel];


}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页