NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];//创建NSTimer
- (void)timerFireMethod:(NSTimer *)timer
{
NSCalendar *calendar = [NSCalendar currentCalendar];
NSString *applydayed = [ NSString stringWithFormat:@"%@" , [dic objectForKey:@"applydayed"] ];
NSDate *applydayedDate = [self FormatterDate:applydayed]; //目标时间
NSDate *today = [NSDate date];//当前时间
unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *d = [calendar components:unitFlags fromDate:today toDate:applydayedDate options:0];//计算时间差
_countdownLabel.text = [NSString stringWithFormat:@"%ld天%ld小时%ld%分%ld秒", [d day], [d hour], [d minute], [d second]];
}
iOS开发之倒计时
最新推荐文章于 2024-09-02 19:45:40 发布