团购倒计时 时间戳转换成 N天,N时,N分,N秒

- (NSString*)getNowTimeWithString:(NSString*)aTimeString{

NSDateFormatter* formater = [[NSDateFormatteralloc]init];

[formatersetDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDate*expireDate = [formaterdateFromString:aTimeString];

NSDate*nowDate = [NSDatedate];

NSString*nowDateStr = [formaterstringFromDate:nowDate];

nowDate = [formaterdateFromString:nowDateStr];

NSTimeIntervaltimeInterval =[expireDatetimeIntervalSinceDate:nowDate];

intdays = (int)(timeInterval/(3600*24));

inthours = (int)((timeInterval-days*24*3600)/3600);

intminutes = (int)(timeInterval-days*24*3600-hours*3600)/60;

intseconds = timeInterval-days*24*3600-hours*3600-minutes*60;

NSString*dayStr;NSString*hoursStr;NSString*minutesStr;NSString*secondsStr;

dayStr = [NSStringstringWithFormat:@"%d",days];

hoursStr = [NSStringstringWithFormat:@"%d",hours];

if(minutes<10)

minutesStr = [NSStringstringWithFormat:@"0%d",minutes];

else

minutesStr = [NSStringstringWithFormat:@"%d",minutes];

if(seconds <10)

secondsStr = [NSStringstringWithFormat:@"0%d", seconds];

else

secondsStr = [NSStringstringWithFormat:@"%d",seconds];

if(hours<=0&&minutes<=0&&seconds<=0) {

return@"活动已经结束!";

}

if(days) {

return[NSStringstringWithFormat:@"%@:%@:%@:%@", dayStr,hoursStr, minutesStr,secondsStr];

}

return[NSStringstringWithFormat:@"%@%@:%@:%@",@"0",hoursStr , minutesStr,secondsStr];

}

你可能感兴趣的:(团购倒计时 时间戳转换成 N天,N时,N分,N秒)