GeT Hour and minute from seconds
#1

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

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)