SA-MP Forums Archive
GeT Hour and minute from 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: GeT Hour and minute from seconds (/showthread.php?tid=515736)



GeT Hour and minute from seconds - audriuxxx - 27.05.2014

Hi,

For ex, i have 7500 seconds.

I want to this seconds display to hours, and how much left to minutes

And where i give that example it will be:

2 hours 5 minutes


Re: GeT Hour and minute from seconds - Lacamora - 27.05.2014

look here
http://forum.sa-mp.com/showpost.php?...&postcount=973


Re: GeT Hour and minute from seconds - Kyance - 28.05.2014

if(seconds[playerid] >= 60)
{
seconds[playerid] = 0;
minutes[playerid]++;
}
else if(minutes[playerid] >= 60)
{
minutes[playerid] = 0;
hours[playerid]++;
}


Re: GeT Hour and minute from seconds - Threshold - 28.05.2014

Actually I made a small function for this when helping a guy in another thread:
pawn Код:
stock ConvertToDaysAndHours(days = 0, hours = 0, minutes = 0, seconds = 0)
{
    while(seconds >= 60) minutes++, seconds -= 60;
    while(minutes >= 60) hours++, minutes -= 60;
    while(hours >= 24) days++, hours -= 24;
    new string[55], fstr[20];
    if(days) format(fstr, sizeof(fstr), (hours || minutes || seconds) ? ("%d days, ") : ("%d days"), days), strins(string, fstr, 0);
    if(hours) format(fstr, sizeof(fstr), (minutes || seconds) ? ("%d hours, ") : ("%d hours"), hours), strins(string, fstr, strlen(string));
    if(minutes) format(fstr, sizeof(fstr), (seconds) ? ("%d minutes, ") : ("%d minutes"), minutes), strins(string, fstr, strlen(string));
    if(seconds) format(fstr, sizeof(fstr), "%d seconds", seconds), strins(string, fstr, strlen(string));
    return string;
}
Example of it's usage:
If you wanted 5 days, 49 hours, 17 minutes and 14 seconds:
pawn Код:
ConvertToDaysAndHours(.days = 4, .hours = 49, .minutes = 17, .seconds = 14);
//Outcome: 7 days, 1 hour, 17 minutes, 14 seconds
If you wanted 3 days, 3 hours and 18 minutes:
pawn Код:
ConvertToDaysAndHours(.days = 3, .hours = 3, .minutes = 18);
//Outcome: 3 days, 3 hours, 18 minutes