I want to take my NSTimeInterval
and format it into a string as 00:00:00 (hours, minutes, seconds). What is the best way to do this?
TimeInterval (née NSTimeInterval ) is a typealias for Double that represents duration as a number of seconds. You'll see it as a parameter or return type for APIs that deal with a duration of time.
A NSTimeInterval value is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.
Since iOS 8.0 there is now NSDateComponentsFormatter
which has a stringFromTimeInterval:
method.
[[NSDateComponentsFormatter new] stringFromTimeInterval:timeInterval];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With