I have to change seconds into minutes, hours. I am already using this code:
int minutes = floor(seconds/60);
int sec = trunc(seconds - minutes * 60);
int hours1 = floor(seconds / (60 * 60));
It works fine, but when "60 minutes" completed it gives 01:61:01 I want timer in this format 01:01:01.
i.e. my minutes does not convert after 60 minutes.
Please suggest me or help me. I am searching lots of code but still not find exact solution.
you can calculate minutes from seconds with bellow formula...
int minutes = (secondsLeft % 3600) / 60;
see the whole code for hours,minutes and seconds bellow...
int hours, minutes, seconds;
hours = secondsLeft / 3600;
minutes = (secondsLeft % 3600) / 60;
seconds = (secondsLeft %3600) % 60;
NSLog(@"\nTime is => %02d:%02d:%02d",hours,minutes,seconds);
Output is : Time is 00:00:06
I have converted secs to minutes.Hope this can help you.
float playListMinsLocal=floorf(songObj.songTime.floatValue);
float playListSecsLocal=songObj.songTime.floatValue-playListMinsLocal+.001;
float playListTotalSecs=(playListMinsLocal*60)+(playListSecsLocal*100);
playListMins+=(int)playListTotalSecs/60;
playListSecs+=(int)playListTotalSecs%60;
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