就在那时,我想我有东西要给你。我创建了一个基本的NSFormatter
子类,它将为您解决问题。您需要做的就是为它提供一个NSNumber
, 包含一个NSTimeInterval
.
.h 和 .m 可在此处获得:https ://github.com/WDUK/WDCountdownFormatter
这是一些使用它的示例代码,是的,它应该尊重语言环境。
WDCountdownFormatter* format = [[WDCountdownFormatter alloc] init];
NSLog(@"70 - %@",[format stringForObjectValue:@(70)]);
NSLog(@"179 - %@",[format stringForObjectValue:@(179)]);
NSLog(@"-10 - %@",[format stringForObjectValue:@(-10)]); // Invalid, will return nil
NSLog(@"0 - %@",[format stringForObjectValue:@(0)]);
NSLog(@"9827193 - %@",[format stringForObjectValue:@(9827193)]);
NSLog(@"1 - %@",[format stringForObjectValue:@(1)]);
生产
// UK English
2012-11-28 23:11:11.453 StackOverflow[28687:c07] 70 - 00:01:10
2012-11-28 23:11:11.456 StackOverflow[28687:c07] 179 - 00:02:59
2012-11-28 23:11:11.457 StackOverflow[28687:c07] -10 - (null)
2012-11-28 23:11:11.458 StackOverflow[28687:c07] 0 - 00:00:00
2012-11-28 23:11:11.458 StackOverflow[28687:c07] 9827193 - 2729:46:33
2012-11-28 23:11:11.459 StackOverflow[28687:c07] 1 - 00:00:01
// Egyptian Arabic
2012-11-28 22:59:54.057 StackOverflow[28400:c07] 70 - ٠٠:٠١:١٠
2012-11-28 22:59:54.659 StackOverflow[28400:c07] 179 - ٠٠:٠٢:٥٩
2012-11-28 22:59:55.473 StackOverflow[28400:c07] -10 - (null)
2012-11-28 22:59:56.464 StackOverflow[28400:c07] 0 - ٠٠:٠٠:٠٠
2012-11-28 22:59:57.311 StackOverflow[28400:c07] 9827193 - ٢٧٢٩:٤٦:٣٣
2012-11-28 23:10:36.657 StackOverflow[28400:c07] 1 - ٠٠:٠٠:٠١