我有三个 int
:
- 分钟
- 秒
- 十(秒/10)
现在,我可以将其格式化为 NSString
: MM:SS.TT
但是:如何将时间跨度加倍并打印出来?我必须使用类似 %
的基本方式来完成它。
Xcode 中有更智能的选项吗?
谢谢
最佳答案
这将为您实现这一目标。我已经拆分了各个步骤来展示它是如何工作的,但是您可以/应该将其压缩以适合您的目的
// Assumes NSInteger values already exist for minutes, seconds and tens
NSTimeInterval span = (minutes * 60) + seconds + ((double)tens / 10.0);
// Double the time-interval
NSTimeInterval twiceSpan = span * 2.0;
// Determine the components
minutes = floor(twiceSpan / 60.0);
seconds = floor(twiceSpan - (minutes * 60.0));
tens = round((twiceSpan - (minutes * 60) - seconds) * 10.0);
// Form a string to show the time as m:s.t where the seconds value is always two digits
NSString *time = [NSString stringWithFormat: @"%i:%02i.%i", minutes, seconds, tens];
关于ios - 在 Xcode 中将时间跨度加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8868724/