Cool utility method to display HH:MM:SS from seconds

When I was developing video recording application, I had to display the time in HH:MM:SS format.
I wrote a utility method which does the same. It takes seconds as input and returns a NSString. Hope this helps iOS community 🙂
NSString * formatHHMMSSStringFromSeconds(int seconds)
    NSString *timeString = @"";
    int minutes = seconds / 60;
    seconds = seconds % 60;
    int hours = 0;
    if(minutes > 60)
        hours = minutes / 60;
        minutes = minutes % 60;
    timeString = [timeString stringByAppendingFormat:@"%02d:%02d:%02d",hours,minutes, seconds];
    return timeString;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s