value to clock format?
#1

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

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;

Reply
#3

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

Use my macros SecToTime or SecToTimeMini
Reply
#4

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;

Reply
#5

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

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;

Reply
#7

Macros is fast !
Reply
#8

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


Forum Jump:


Users browsing this thread: 3 Guest(s)