Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTimeInterval Formatting

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?

like image 842
Baub Avatar asked Nov 14 '11 21:11

Baub


People also ask

What is NSTimeInterval?

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.

Is NSTimeInterval in seconds?

A NSTimeInterval value is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.


1 Answers

Since iOS 8.0 there is now NSDateComponentsFormatter which has a stringFromTimeInterval: method.

[[NSDateComponentsFormatter new] stringFromTimeInterval:timeInterval]; 
like image 198
Johan Kool Avatar answered Oct 04 '22 06:10

Johan Kool