Convert miliseconds to regular time? -
sciman001 - 04.05.2011
Hi all. I have a thing that returns miliseconds. I wanna make a function like this:
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!
Re: Convert miliseconds to regular time? -
Steven82 - 04.05.2011
There are already functions for that...use the wiki.
gettime
getdate
Re: Convert miliseconds to regular time? -
sciman001 - 04.05.2011
not what i mean! how i say it? um... like... ok.. on my gm init, i got this:
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.
Re: Convert miliseconds to regular time? -
MadeMan - 04.05.2011
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.
Re: Convert miliseconds to regular time? -
BigETI - 04.05.2011
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);