Converting seconds to HH:MM:SS - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Converting seconds to HH:MM:SS (
/showthread.php?tid=254363)
Converting seconds to HH:MM:SS -
Hobod - 10.05.2011
I've attempted this myself and failed. I found a snippet somewhere on the net that looked as if it worked and it does to a point. But it has a problem where if youve got an hour and no minutes then you end up with it not counting right.
COuld anyone give me a working way of converting seconds to a format of HH:MM:SS.
Thanks in advance
Re: Converting seconds to HH:MM:SS -
Zh3r0 - 10.05.2011
From ******:
Код:
1 second = 0.000277777778 hours
1 second = 0.0166666667 minutes
Good luck!
Remember to use floatround(); ! To round seconds from 0.67788000 for example to 1.0000000
Re: Converting seconds to HH:MM:SS -
JaTochNietDan - 10.05.2011
Here's a stock function I whipped up quickly to convert it for you:
pawn Код:
/*Usage: The seconds parameter should be the amount of seconds you want to convert and
the rest of the parameters should be variables to store the integer value for each of the
time values*/
stock formatSeconds(seconds, &hours_left, &minutes_left, &seconds_left)
{
hours_left = seconds/60/60;
minutes_left = (seconds - hours_left*60*60)/60;
seconds_left = (seconds - hours_left*60*60 - minutes_left*60);
return 1;
}
Usage example:
pawn Код:
new
hours,
minutes,
seconds;
formatSeconds(5000, hours, minutes, seconds);
printf("Hours: %d, Minutes: %d, Seconds: %d in 5000 seconds", hours, minutes, seconds);
Hope that's what you were looking for!
Re: Converting seconds to HH:MM:SS -
Hobod - 10.05.2011
Well what im using this for is i'm attempting to make a total playing time that shows up in the stats.
I'll try your function as soon as i get chance
Re: Converting seconds to HH:MM:SS -
Zh3r0 - 10.05.2011
Quote:
Originally Posted by Hobod
Well what im using this for is i'm attempting to make a total playing time that shows up in the stats.
I'll try your function as soon as i get chance
|
ladmin has a good way of getting player's time by using the seconds since 1970.
Re: Converting seconds to HH:MM:SS -
Hobod - 10.05.2011
JaTochs function did it perfect for me, thanks both of you ^^
Re: Converting seconds to HH:MM:SS -
Calgon - 10.05.2011
Next time, take a look at gettime() and Unix Timestamps.