标签:
时间字符串从网上请求下来的字符串NSString * expireDatetime = [dictionary objectForKey:@"expireDatetime"];
因为剩余时间有可能为零
//剩余时间可能出现null的格式 运行的时候会出错 所以要把这样的信息过滤 if([expireDatetime isKindOfClass:[NSNull class]]) { self.timeLabel.text = @"剩余:00:00:00"; } else { //定义时间戳样式 NSDateFormatter * formatter = [[NSDateFormatter alloc]init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.0"; //结束时间 NSDate * endDate = [formatter dateFromString:expireDatetime]; //获取剩余时间 NSTimeInterval interval = [endDate timeIntervalSinceNow]; //获取时分秒 int HH = (int)interval / 3600; int MM = (int)interval / 60 % 60; int SS = (int)interval % 60; if(HH < 0 || MM < 0 || SS < 0) { self.timeLabel.text = @"剩余:00:00:00"; } else { self.timeLabel.text = [NSString stringWithFormat:@"剩余:%.2d:%.2d:%.2d",HH,MM,SS]; } }
标签:
原文地址:http://www.cnblogs.com/huoxingdeguoguo/p/4614405.html