Search code examples
objective-ciphonenstimeintervalsecondsminute

How to convert an NSTimeInterval (seconds) into minutes


I've got an amount of seconds that passed from a certain event. It's stored in a NSTimeInterval data type.

I want to convert it into minutes and seconds.

For example I have: "326.4" seconds and I want to convert it into the following string: "5:26".

What is the best way to achieve this goal?

Thanks.


Solution

  • pseudo-code:

    minutes = floor(326.4/60)
    seconds = round(326.4 - minutes * 60)