NSDate从现在倒数到NSDate [英] NSDate countdown from NOW to NSDate
本文介绍了NSDate从现在倒数到NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何显示HH:mm:ss格式的倒计时,从现在到将来会发生的所需NSDate?
How can I show a countdown in HH:mm:ss format from NOW to a desired NSDate that will happen in the future?
推荐答案
您必须使用计时器来打勾日期。
You have to use a timer for ticking the date.
存储将来的日期,并继续减去将来的日期-[今天的日期] ...
Store a future date, and keep on substracting future date - [nsdate today]...
以秒为单位计算时间,并将其计算为小时,分钟,秒...
Calculate the time in seconds and calculate it into Hours, minutes, seconds...
//属性 NSDate * nowDate,* futureDate
futureDate=...;
nowDate=[NSDate date];
long elapsedSeconds=[nowDate timeIntervalSinceDate:futureDate];
NSLog(@"Elaped seconds:%ld seconds",elapsedSeconds);
NSInteger seconds = elapsedSeconds % 60;
NSInteger minutes = (elapsedSeconds / 60) % 60;
NSInteger hours = elapsedSeconds / (60 * 60);
NSString *result= [NSString stringWithFormat:@"%02ld:%02ld:%02ld", hours, minutes, seconds];
这对您来说很方便... 请仔细检查项目 ...
This will come handy for you...kindly check the project...
这篇关于NSDate从现在倒数到NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文