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 minuti, sekunde, string[128];
if(vreme > 59)
{
minuti = floatround(vreme/60);
sekunde = floatround(vreme - minuti*60);
if(sekunde > 9) format(string, sizeof(string), "%d:%d", minuti, sekunde);
else format(string, sizeof(string), "%d:0%d", minuti, sekunde);
}
else
{
sekunde = floatround(vreme);
if(sekunde > 9) format(string, sizeof(string), "0:%d", sekunde);
else format(string, sizeof(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 minuti, sekunde, string[128];
if(vreme > 59)
{
minuti = floatround(vreme/60);
sekunde = floatround(vreme - minuti*60);
if(sekunde > 9) format(string, sizeof(string), "%d:%d", minuti, sekunde);
else format(string, sizeof(string), "%d:0%d", minuti, sekunde);
}
else
{
sekunde = floatround(vreme);
if(sekunde > 9) format(string, sizeof(string), "0:%d", sekunde);
else format(string, sizeof(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(string, sizeof string, "%02i:%02i", (seconds / 60) % 60, seconds % 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 minuti, sekunde, string[128];
if(vreme > 59)
{
minuti = floatround(vreme/60);
sekunde = floatround(vreme - minuti*60);
if(sekunde > 9) format(string, sizeof(string), "%d:%d", minuti, sekunde);
else format(string, sizeof(string), "%d:0%d", minuti, sekunde);
}
else
{
sekunde = floatround(vreme);
if(sekunde > 9) format(string, sizeof(string), "0:%d", sekunde);
else format(string, sizeof(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(value, 60),
str[30];
format(str, sizeof(str), "%02i:%02i", min, sec);
return str;
}
stock Euclideandiv(dividende, diviseur, &reste = 0)
{
new
result = 0;
for(; dividende >= diviseur; result++)
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)