Converting seconds to hours and minutes
#3

34000 / 3600 gives a decimal number. That should never happen and you should only ever get whole numbers.
pawn Code:
new totaltime = 34000; // this is your initial value, here for reference
new remaining; // temporary storage

remaining = totaltime % 3600; // remaining seconds after subtracting hours

new hours = (totaltime - remaining) / 3600;
new seconds = remaining % 60;
new minutes = (remaining - seconds) / 60;

// will give: 9 hours, 26 minutes, 40 seconds
Could probably be optimized a bit more, but that should work. Very important not to change the order of the statements.
Reply


Messages In This Thread
Converting seconds to hours and minutes - by Cypress - 08.07.2012, 15:00
Re: Converting seconds to hours and minutes - by ViniBorn - 08.07.2012, 15:15
Re: Converting seconds to hours and minutes - by Vince - 08.07.2012, 15:40

Forum Jump:


Users browsing this thread: 1 Guest(s)