I execute a function to convert unix time (dd-mm-yyyy)
stock UnixToTime(x)
{
new year = 1970;
new dia = 1;
new mes = 1;
while(x > 86400)
{
x -= 86400;
dia ++;
if(dia == getTotalDaysInMonth(mes, year))
{
dia = 1;
mes ++;
if (mes >= 12)
{
year ++;
mes = 1;
}
}
}
printf("%i-%i-%i", dia, mes, year);
return x;
}
but does not work.
I am testing a function with 1458342000 (today ...), but I am printing> 13-3-2022, what kind of error?
#define IsLeapYear(%1) ((%1 % 4 == 0 && %1 % 100 != 0) || %1 % 400 == 0)
getTotalDaysInMonth:
stock getTotalDaysInMonth(_month, year)
{
new dias[] = {
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
};
return ((_month >= 1 && _month <= 12) ? (dias[_month-1] + (IsLeapYear(year) && _month == 2 ? 1 : 0)) : 0);
}
iZume source
share