Converting seconds to HH:MM:SS
#1

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
Reply
#2

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
Reply
#3

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!
Reply
#4

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
Reply
#5

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.
Reply
#6

JaTochs function did it perfect for me, thanks both of you ^^
Reply
#7

Next time, take a look at gettime() and Unix Timestamps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)