Converting seconds to hours and minutes - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Converting seconds to hours and minutes (
/showthread.php?tid=357832)
Converting seconds to hours and minutes -
Cypress - 08.07.2012
I have used search and didn't found something that would really solve my problem. I'm converting seconds to hours and minutes like that:
pawn Code:
pData[playerid][p_online_time] / 3600 // hours
(pData[playerid][p_online_time / 60) % 60 // minutes
My problem is that it doesn't convert big values like 34000. It doesn't show anything.
Is there any other way that would work?
Re: Converting seconds to hours and minutes -
ViniBorn - 08.07.2012
if p_online_time is a value in seconds :
pawn Code:
//minutes
pData[playerid][p_online_time] / 60
//hours
pData[playerid][p_online_time] / 3600
Re: Converting seconds to hours and minutes -
Vince - 08.07.2012
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.