Convert miliseconds to regular time?
#1

Hi all. I have a thing that returns miliseconds. I wanna make a function like this:
pawn Код:
ConvertMsToTime(ms);
And it will convert the miliseconds to this time format:
Код:
[Years]:[Months:][Days] - [Hours]:[Minutes]:[Seconds]
I know it wond be online for years (probably) but its nice to have. THANZ!
Reply
#2

There are already functions for that...use the wiki.
gettime
getdate
Reply
#3

not what i mean! how i say it? um... like... ok.. on my gm init, i got this:

pawn Код:
sta = GetTickCount();
and on my gm exit, i got this:
pawn Код:
sto = GetTickCount();
o = sto - sta;
printf("Server online for: %i ms!", o);
the problem is that it prints in miliseconds, not that format. I wanna calculate how many days, years, months, hours, minutes, and seconds the miliseconds are equal to... u c wut i mean? i already no how to use getdate and gettime.
Reply
#4

pawn Код:
stock ConvertMsToTime(ms)
{
    new seconds = ms/1000;
    new string[32];
    format(string, sizeof(string), "%02d:%02d:%02d - %02d:%02d:%02d",
        seconds/31536000, (seconds%31536000)/2592000, (seconds%2592000)/86400,
        (seconds%86400)/3600, (seconds%3600)/60, seconds%60);
    return string;
}
pawn Код:
sto = GetTickCount();
o = sto - sta;
printf("Server online for: %s", ConvertMsToTime(o));
But years and months are pointless to convert because you can't have that big values in milliseconds.
Reply
#5

pawn Код:
stock GetDateAndTimeOfMs(millisecond, &year, &month, &day, &hour, &minute, &second)
{
    new accuracity;
    tickcount(accuracity);
    while(millisecond > accuracity-1)
    {
        millisecond = millisecond-accuracity;
        second++;
    }
    while(second > 59)
    {
        second = second-60;
        minute++;
    }
    while(minute > 59)
    {
        minute = minute-60;
        hour++;
    }
    while(hour > 23)
    {
        hour = hour-24;
        day++;
    }
    while(day > 27)
    {
        day = day-28;
        month++;
    }
    while(month > 11)
    {
        month = month-12;
        year++;
    }
}
Usage:
pawn Код:
GetDateAndTimeOfMs(milliseconds, &year, &month, &day, &hour, &minute, &second);
Example:
pawn Код:
new year, month, day, hour, minute, second;
GetDateAndTimeOfMs(1000000000, year, month, day, hour, minute, second);
printf("Time: %d years | %d months | %d days | %d hours | %d minutes | %d seconds", year, month, day, hour, minute, second);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)