SA-MP Forums Archive
Convert seconds to hours, minutes, seconds - 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: Convert seconds to hours, minutes, seconds (/showthread.php?tid=547881)



Convert seconds to hours, minutes, seconds - kurta999 - 25.11.2014

Hi.

I'm very bad at time converting, so please someone complete this function, where I would give player online time in seconds, and it will convert these seconds to hours, minutes and seconds format. Thanks.

pawn Код:
stock ConvertTime(seconds, &hours, &minutes, &seconds)
{
// :D:D
}



Re: Convert seconds to hours, minutes, seconds - AnthonyTimmers - 25.11.2014

Don't know what variables you're using but I'll go with totalSeconds, hours, minutes and seconds:

pawn Код:
new temp, hours, minutes, seconds;

temp = totalSeconds % 3600;

hours = (totalSeconds - temp) / 3600;
minutes = (temp - (temp % 60)) / 60;
seconds = temp % 60;



Re: Convert seconds to hours, minutes, seconds - Banana_Ghost - 26.11.2014

https://sampforum.blast.hk/showthread.php?pid=2069763#pid2069763
http://southclawjk.wordpress.com/201...tring-snippet/
This is very useful and simple information supplied by [HLF]Southclaw.


Re: Convert seconds to hours, minutes, seconds - M4D - 26.11.2014

you can use this

pawn Код:
stock Sec2HMS(secs, &hours, &minutes, &seconds)
{
  if (secs < 0) return false;
  minutes = secs / 60;
  seconds = secs % 60;
  hours = minutes / 60;
  minutes = minutes % 60;
  return 1;
}


new H,M,S,string[50];
new sec = /*Your total seconds here*/
Sec2HMS(sec,H,M,S);
format(string,sizeof(string),"%d:%d:%d",H,M,S);