SA-MP Forums Archive
seconds to minutes and 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: seconds to minutes and seconds (/showthread.php?tid=246556)



seconds to minutes and seconds - Pooh7 - 04.04.2011

how to convert this:
pawn Код:
new variable = 650, string[64];
format(string, 64, "Jail time left: %d seconds", variable);
to

Jail time left: 10:50
(10 minutes and 50 seconds)


Re: seconds to minutes and seconds - Donya - 04.04.2011

pawn Код:
new variable = 650, string[64];
format(string, 64, "Jail time left: %s seconds", TimeConvert(variable));

TimeConvert(time) {
    new minutes,seconds,string[128];
    if(time > 59){
        minutes = floatround(time/60);
        seconds = floatround(time - minutes*60);
        if(seconds>9)format(string,sizeof(string),"%d:%d",minutes,seconds);
        else format(string,sizeof(string),"%d:0%d",minutes,seconds);
    }
    else{
        seconds = floatround(time);
        if(seconds>9)format(string,sizeof(string),"0:%d",seconds);
        else format(string,sizeof(string),"0:0%d",seconds);
    }
    return string;
}



Re: seconds to minutes and seconds - Pooh7 - 04.04.2011

Thank you


Re: seconds to minutes and seconds - Joe Staff - 04.04.2011

Or more simply
pawn Код:
stock strtime(seconds)
{
    new string[16];
    format(string,16,"%02d:%02d",seconds/60,seconds%60);
    return string;
}
pawn Код:
printf("Time Remaining:  %s",strtime(361));
Will print
Код:
Time Remaining:  06:01