seconds to minutes and seconds
#1

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

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

Thank you
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)