Posts

Showing posts with the label Objective-C

iOS Convert Seconds into hours,minutes and seconds

Hi all, In building iPhone applications you may have come across situations that you count some time in seconds, but wish to let the user view it in a more readable format such as 1 hour 38 minutes and 44 seconds. Here is a piece of code that I wrote if you need to get this done in your code. - ( NSString *)timeFormatted:( int )totalSeconds {     int seconds = totalSeconds % 60 ;     int minutes = (totalSeconds / 60 ) % 60 ;     int hours = totalSeconds / 3600 ;         NSString *timeString =@"";     NSString *formatString=@"";     if(hours > 0){         formatString=hours==1?@"%d hour":@"%d hours";         timeString = [timeString stringByAppendingString:[NSString stringWithFormat:formatString,hours]];     }     if(minutes > 0 || hours > 0 ){         formatString=minutes==1?@" %d minute...