09.01.2012, 04:41
Could someone please provide me with the method to convert seconds to hours, minutes and seconds?
public secs2hms(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;
secs2hms(4126623,h,m,s);
printf("4126623 secs : %d:%d:%d",h,m,s);
new seconds = SOME_VALUE, minutes, hours, days;
while(seconds > 59)
{
seconds -= 60;
minutes++;
}
while(minutes > 59)
{
minutes -= 60;
hours++;
}
while(hours > 23)
{
hours -= 24;
days++;
}
Can you provide an example on how to use it? It's not very clear. I attempted it, but got invalid argument errors. How does the function know how many seconds to convert from, there's no argument for that?!
|
format(ps, sizeof(ps), "In-game [AFK for %s]", ConvertTime(secs_away));
stock secs2hms(secs,&hours,&minutes,&seconds) {if (secs<0) return false;minutes = secs / 60; seconds = secs % 60;hours = minutes / 60; minutes = minutes % 60;return 1;}
new MyKnownSeconds = 3661;
new Seconds;
new Minutes;
new Hours;
public OnFilterScriptInit()
{
new MyKnownSeconds = 3661;
new Seconds;
new Minutes;
new Hours;
secs2hms(/*input*/ MyKnownSeconds, /*output*/Hours,Minutes,Seconds);//Assign Hours,Minutes,Seconds the correct values, you can replace MyKnownSeconds by an number also, eg 3661
printf("H: %d M: %d S: %d",Hours,Minutes,Seconds);
return 1;
}
H: 1 M: 1 S: 1