SA-MP Forums Archive
value to clock format? - 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: value to clock format? (/showthread.php?tid=611593)



value to clock format? - Lirbo - 08.07.2016

Let's say I've a number with the value of 600, how I can make a string that would show it as 10:00? (600 seconds = 10 minutes)


Re: value to clock format? - Dusan01 - 08.07.2016

here u go a function:
PHP код:
stock ConvertTime(vreme)
{
    new 
minutisekundestring[128];
    if(
vreme 59)
    {
        
minuti floatround(vreme/60);
        
sekunde floatround(vreme minuti*60);
        if(
sekunde 9format(stringsizeof(string), "%d:%d"minutisekunde);
        else 
format(stringsizeof(string), "%d:0%d"minutisekunde);
    }
    else
    {
        
sekunde floatround(vreme);
        if(
sekunde 9format(stringsizeof(string), "0:%d"sekunde);
        else 
format(stringsizeof(string), "0:0%d"sekunde);
    }
    return 
string;




Re: value to clock format? - AbyssMorgan - 08.07.2016

https://github.com/AbyssMorgan/Time-.../timestamp.inc

Use my macros SecToTime or SecToTimeMini


Re: value to clock format? - Konstantinos - 08.07.2016

Quote:
Originally Posted by Dusan01
Посмотреть сообщение
here u go a function:
PHP код:
stock ConvertTime(vreme)
{
    new 
minutisekundestring[128];
    if(
vreme 59)
    {
        
minuti floatround(vreme/60);
        
sekunde floatround(vreme minuti*60);
        if(
sekunde 9format(stringsizeof(string), "%d:%d"minutisekunde);
        else 
format(stringsizeof(string), "%d:0%d"minutisekunde);
    }
    else
    {
        
sekunde floatround(vreme);
        if(
sekunde 9format(stringsizeof(string), "0:%d"sekunde);
        else 
format(stringsizeof(string), "0:0%d"sekunde);
    }
    return 
string;

You can use "%0xi" or "%0xd" whereas x is the number of zeros will be added if the digits are less.

PHP код:
ConvertTime(seconds)
{
    new 
string[10];
    
format(stringsizeof string"%02i:%02i", (seconds 60) % 60seconds 60);
    return 
string;




Re: value to clock format? - AbyssMorgan - 08.07.2016

Quote:
Originally Posted by Dusan01
Посмотреть сообщение
here u go a function:
PHP код:
stock ConvertTime(vreme)
{
    new 
minutisekundestring[128];
    if(
vreme 59)
    {
        
minuti floatround(vreme/60);
        
sekunde floatround(vreme minuti*60);
        if(
sekunde 9format(stringsizeof(string), "%d:%d"minutisekunde);
        else 
format(stringsizeof(string), "%d:0%d"minutisekunde);
    }
    else
    {
        
sekunde floatround(vreme);
        if(
sekunde 9format(stringsizeof(string), "0:%d"sekunde);
        else 
format(stringsizeof(string), "0:0%d"sekunde);
    }
    return 
string;

First, learn how to use format ~.~
https://sampwiki.blast.hk/wiki/Format


Re: value to clock format? - Dayrion - 08.07.2016

Mine:
PHP код:
stock SecToMin(value)
{
    new 
sec value%60,
        
min Euclideandiv(value60),
        
str[30];
    
format(strsizeof(str), "%02i:%02i"minsec);
    return 
str;
}
stock Euclideandiv(dividendediviseur, &reste 0)
{
    new
        
result 0;
    for(; 
dividende >= diviseurresult++)
        
dividende -= diviseur;
    
    
reste dividende;    
    return 
result;




Re: value to clock format? - AbyssMorgan - 08.07.2016

Macros is fast !


Re: value to clock format? - Lirbo - 08.07.2016

Thanks a lot everybody +REP (sorry Kostantinos I can't rep u for some reason XD, probably cuz I gave reps only to u lately <3)