In my project, I have used NSDateFormatter to properly format the dates displayed in my application. To be more specific, here is an example:
English: 12:34 am
Arabic: ١٢:٣٤ ص
Looks great, shows the numerals that I need. However, I have a time counter/timer that is counting up/down in the app:
01:31:22 // HH:mm:ss
How would I properly localize this counter to be displayed as:
٠١:٣١:٢٢
I checked NSDateFormatter, but it doesn’t really represent this particular use case, as far as I can see. NSNumberFormatter seems to work for currencies and percentages.
Why NSDateFormatter Doesn’t Make Sense:
Because it has NSTimeZone property, and has am/pm suffix which are both useless when we want to use counters.
Right then, I think I have something for you. I’ve created a basic
NSFormattersubclass, which will do the trick for you. All you need to do, it provide it with anNSNumber, that contains anNSTimeInterval.The .h and .m are available here: https://github.com/WDUK/WDCountdownFormatter
And here is some example code using it, and yes, it should respect locales.
Produces