15.09.2016, 11:58
I wrote a function that can help you to convert your unix time to normal time.
Function:
Example Usage:
Function:
Code:
forward isLeap(y); public isLeap(y){ return ((y)%4==0&&((y)%100!=0||(y)%400==0)); } stock unixtodate(timestamp) { new rtrn[128]; if(timestamp > 0) { new year, dayInSeconds, daysInYear, daysInLYear, days, tmpDays, monthsInDays[12], month, day; year = 1970; dayInSeconds = 86400; daysInYear = 365; daysInLYear = daysInYear+1; days = (timestamp/dayInSeconds); tmpDays = days+1; month = 11; while(tmpDays>=daysInYear){ year++; if(isLeap(year)){ tmpDays-=daysInLYear; } else{ tmpDays-=daysInYear; } } if(isLeap(year)){ tmpDays--; monthsInDays = {-1,30,59,90,120,151,181,212,243,273,304,334}; } else{ monthsInDays = {0,31,59,90,120,151,181,212,243,273,304,334}; } while(month>0){ if(tmpDays>monthsInDays[month]){ break; } month--; } day=tmpDays-monthsInDays[month]; month++; format(rtrn, sizeof(rtrn), "%d-%d-%d", year, month, day); return rtrn; } format(rtrn, sizeof(rtrn), "1970-1-1"); return rtrn; }
Code:
printf("%s",unixtodate(1473939194));