Quote:
Originally Posted by CyNiC
Some time ago I was searching for convert timestamp to date and the only way that I found was use a plugin.
I found this on Pawn source, I think that it can be useful to someone else(be aware of your time zone).
pawn Код:
stock timestamptodate(sec1970,&year=0,&month=0,&day=0,&hour=0,&minute=0,&second=0) //By CompuPhase { #define SECONDS_PER_MINUTE 60 #define SECONDS_PER_HOUR 3600 #define SECONDS_PER_DAY 86400 #define SECONDS_PER_YEAR 31556952 /* based on 365.2425 days per year */ new monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; new days, seconds;
/* find the year */ for (year = 1970; ; year += 1) { days = 365 + _:((year & 0x03) == 0); /* clumsy "leap-year" routine, fails for 2100 */ seconds = days * SECONDS_PER_DAY; if (seconds > sec1970) break; sec1970 -= seconds; } /* if */
/* find the month */ for (month = 1; ; month += 1) { days = monthdays[month - 1]; seconds = days * SECONDS_PER_DAY; if (seconds > sec1970) break; sec1970 -= seconds; } /* if */
/* find the day */ for (day = 1; sec1970 >= SECONDS_PER_DAY; day += 1) sec1970 -= SECONDS_PER_DAY;
/* find the hour */ for (hour = 0; sec1970 >= SECONDS_PER_HOUR; hour += 1) sec1970 -= SECONDS_PER_HOUR;
/* find the minute */ for (minute = 0; sec1970 >= SECONDS_PER_MINUTE; minute += 1) sec1970 -= SECONDS_PER_MINUTE;
/* remainder is the number of seconds */ second = sec1970; }
|
You are just way too stupid to use the search here.
I already found earlier many functions to get the date back. Look into my signature.