07.10.2012, 07:04
(
Последний раз редактировалось Jochemd; 07.10.2012 в 08:18.
)
new ts = gettime() - 2 * 86400,ts2[6];
printf("Current Time Stamp: %d",ts);
TimestampToDate(ts, ts2[0], ts2[1], ts2[2], ts2[3], ts2[4], ts2[5], 5 ,30);
printf("Current Date: %d/%d/%d and Time: %d:%d:%d", ts2[0], ts2[1], ts2[2], ts2[3], ts2[4], ts2[5]);
[22:41:17] Current Time Stamp: 1354381877 [22:41:17] Current Date: 2012/12/3 and Time: 22:41:17
new ts = timestamp(),ts2 = gettime();
printf("Current Time Stamp: %d and %d",ts,ts2);
[22:55:36] Current Time Stamp: 1354748136 and 1354555536
stock timestamp()
{
new
h,
m,
s,
d,
n,
y;
gettime(h, m, s);
getdate(y, n, d);
return mktime(h, m, s, d, n, y);
}
/*----------------------------------------------------------------------------*-
Function:
mktime
Params:
hour - Hour of time.
minute - Minute of time.
second - Second of time.
day - Day of date.
month - Month of date.
year - Year of date.
Return:
Timestame of a given date and time.
Notes:
Uses a check system as it's used in Player_OnPlayerDisconnect when lots of
people can disconnect at the same time on gmx so has code to make large
numbers of simultaneous calls more efficient.
-*----------------------------------------------------------------------------*/
stock mktime(hour, minute, second, day, month, year)
{
static
days_of_month[12] =
{
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
},
lMinute,
lHour,
lDay,
lMonth,
lYear,
lMinuteS,
lHourS,
lDayS,
lMonthS,
lYearS;
if (year != lYear)
{
lYearS = 0;
for (new j = 1970; j < year; j++)
{
lYearS += 31536000;
if ((!(j % 4) && (j % 100)) || !(j % 400)) lYearS += 86400;
}
lYear = year;
}
if (month != lMonth)
{
lMonthS = 0;
month--;
for (new i = 0; i < month; i++)
{
lMonthS += days_of_month[i] * 86400;
if ((i == 1) && ((!(year % 4) && (year % 100)) || !(year % 400))) lMonthS += 86400;
}
lMonth = month;
}
if (day != lDay)
{
lDayS = day * 86400;
lDay = day;
}
if (hour != lHour)
{
lHourS = hour * 3600;
lHour = hour;
}
if (minute != lMinute)
{
lMinuteS = minute * 60;
lMinute = minute;
}
return lYearS + lMonthS + lDayS + lHourS + lMinuteS + second - 279000;
}
stock DateToTimestamp(str[11])
new hello = DateToTimestamp("06.10.2013"); // 'hello' now contains 1381104000, which is correct for that day.
new y, m, d, h, mi, s; getdate(y, m, d); gettime(h, mi, s); format(bandate, sizeof(bandate), "%d/%d/%d - %d:%d:%d", y,m,d,h,mi,s); TimestampToDate(bantime, y, m, d, y, m, s, 1); format(expiredate, sizeof(expiredate), "%d/%d/%d - %d:%d:%d", y,m,d,h,mi,s);
TimestampToDate(bantime, y, m, d, y, m, s, 1);
TimestampToDate(bantime, y, m, d, h, mi, s, 1);
if(minute > 59) { minute = 0; hour ++; } if(hour > 23) { hour -= 24; day ++; if(day > MonthTimes[month][IsLeapYear(year)]) { day = 1; month ++; if(month > 12) { month = 1; year ++; } } }
[21:30:24] [debug] Run time error 4: "Array index out of bounds" [21:30:24] [debug] Accessing element at index 24 past array upper bound 11 [21:30:24] [debug] AMX backtrace: [21:30:24] [debug] #0 000066a4 in ?? (0x00000720, 0x000068c8, 0x000068c8, 0x000068c8, 0x000068c4, 0x000068c0, 0x000068c8, 0x00000001, 0x00000000) from aaa.amx [21:30:24] [debug] #1 0000689c in public cmd_check (0x00000000, 0x00002aac) from aaa.amx [21:30:24] [debug] #2 native CallLocalFunction () [00472ad0] from samp-server.exe [21:30:24] [debug] #3 000003e0 in public OnPlayerCommandText (0x00000000, 0x00002a90) from aaa.amx
CMD:check(playerid, params[]) { #pragma unused params new buff[64], temp, hour, minute; TimestampToDate(pData[playerid][last_session], temp, temp, temp, hour, minute, temp, 1); format( buff, sizeof ( buff ), "H: %02d M: %02d", hour, minute); SendClientMessage(playerid, -1, buff); return 1; }