Re: AW: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 07.10.2012
Quote:
Originally Posted by s3rserii
can u reupload the Example ?
|
I will when I get on my laptop.
Edit: Updated.
AW: TimestampToDate.inc - Convert a timestamp to a date! -
s3rserii - 07.10.2012
fine thx
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Ballu Miaa - 03.12.2012
NOTE: Sorry for bumping an Old Thread.
While using ****** timestamp() function with mktime() along with Your TimeStampDate() function, I was getting 5/12/2012 and 23:42:04 as the date and time according to current Timestamp in GMT +5:30. and gettime() was returning this Timestamp which were had two days in addition to this timestamp according to the Indian Time Zone GMT+5:30!
But then i used gettime() function to provide me the Current TimeStamp and I subtracted 2 * 86400 from this Timestamp , Then i used this new TimeStamp with your TimeStampDate() function and i got 3/12/2012 and 18:32:45. Which was almost accurate!
I think ****** timestamp() calculator isnt corrent. Your TimeStampDate() works great for me now!! I love this , you dont know what you have done for me. Fucking Awesome work my bro. Thanks to you so much! Rep+8.
- BMiaa
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Ballu Miaa - 03.12.2012
EDIT: I just got to know. Both the function
timestamp() which uses mktime() by ****** and the native function of SA-MP
gettime() to get Current Time Stamps according to the GMT of a region are not Correct.
1. gettime() - Which Returns Current Time Stamps -
Bug: Exact two Days greater then the Current Timestamps for Indian Time Zone: GMT +5:30.
Fix: Subtract 2 * 86400 from the returned TimeStamps.
2. timestamp() - Which Returns Current TIme Stamps -
Bug: Returns incorrect number of seconds since the epoch.
Fix: Subtract 279000 from the received timestamps.
The proof i would say. Or can say Code for correcting Time Stamps fix gettime() SA-MP native.
pawn Код:
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]);
The Output was !!
Код:
[22:41:17] Current Time Stamp: 1354381877
[22:41:17] Current Date: 2012/12/3 and Time: 22:41:17
Second on Getting the TimeStamp using gettime() as well as with timestamp by ******.
pawn Код:
new ts = timestamp(),ts2 = gettime();
printf("Current Time Stamp: %d and %d",ts,ts2);
The Output was:
Код:
[22:55:36] Current Time Stamp: 1354748136 and 1354555536
EDIT:
Here is the Correct code of timestamp() and mktime() by ******.
mktime() is fixed also which returns TimeStamps for any particular date.
pawn Код:
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;
}
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 12.12.2012
Update 12/12/12 v1.2
Fixed Ballu Miaa's issue. Now 2 days are subtracted before even starting the loop.
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Ballu Miaa - 13.12.2012
Quote:
Originally Posted by Jochemd
Update 12/12/12 v1.2
Fixed Ballu Miaa's issue. Now 2 days are subtracted before even starting the loop.
|
Haha Thanks bro!
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 06.04.2013
UPDATE 06/04/2013: v2.0. This library contains a new stock: DateToTimestamp. I will explain this as well.
pawn Код:
stock DateToTimestamp(str[11])
You could compare this with strtotime/mktime in PHP. The only parameter is a string, which is the date that should be converted to a timestamp. It should be in the following format:
06.04.2013. The "." here is the splitter. It can be changed to any character you wish (as long as you don't use numeric characters, it will probably work). It should be changed by redefining "#SPLITTER" after including this library.
Example:
pawn Код:
new hello = DateToTimestamp("06.10.2013"); // 'hello' now contains 1381104000, which is correct for that day.
Re: TimestampToDate.inc - Convert a timestamp to a date! -
shaPP - 12.02.2014
I rly need this but i think it is a little bugged
Код:
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);
Output: 2014/2/12 - 6:50:32(bandate) 5/51/12 - 6:50:32(expiredate) 1392180692(unix)
Checked unix online and it is good
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Drake1994 - 13.02.2014
Код:
TimestampToDate(bantime, y, m, d, y, m, s, 1);
instead use this:
Код:
TimestampToDate(bantime, y, m, d, h, mi, s, 1);
Re: TimestampToDate.inc - Convert a timestamp to a date! -
shaPP - 14.02.2014
OMFG didn't saw that little mistake ;d Thanks a lot :d gonna try it right now
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 30.03.2014
And, did it work now? Just curious.
Respuesta: TimestampToDate.inc - Convert a timestamp to a date! -
MugiwaraNoLuffy - 31.03.2014
SQLite has some functions with timestamp and dates. Are they faster than these?
Re: Respuesta: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 31.03.2014
Quote:
Originally Posted by MugiwaraNoLuffy
SQLite has some functions with timestamp and dates. Are they faster than these?
|
It's sort of a detour to use SQLite for such things, don't you think so?
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Zio - 06.04.2014
I set GMT 4 and hour became 27. Maybe it's bug. I fixed it so. Sorry for my bad english.
Код:
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 ++;
}
}
}
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 08.04.2014
Quote:
Originally Posted by Zio
I set GMT 4 and hour became 27. Maybe it's bug. I fixed it so. Sorry for my bad english.
|
Thanks for your reply, I fixed it
Respuesta: Re: Respuesta: TimestampToDate.inc - Convert a timestamp to a date! -
MugiwaraNoLuffy - 09.04.2014
Quote:
Originally Posted by Jochemd
It's sort of a detour to use SQLite for such things, don't you think so?
|
No, because C++ is much faster than Pawn natives (operators are also natives). Also, it just requieres one short query.
Respuesta: Re: TimestampToDate.inc - Convert a timestamp to a date! -
MugiwaraNoLuffy - 10.04.2014
Quote:
Originally Posted by ******
SOME operators are natives - notably the Float operators, most aren't.
|
Sorry, you're right.
Re: TimestampToDate.inc - Convert a timestamp to a date! -
sammp - 30.06.2014
Sorry for bumping but how would I use this to calculate the current time.
Im tired and puzzled
Re: TimestampToDate.inc - Convert a timestamp to a date! -
Jochemd - 30.06.2014
You shouldn't use this to calculate the current time, since
gettime() and
getdate() are proper enough for that.
Re: TimestampToDate.inc - Convert a timestamp to a date! -
PapaSmerf - 24.07.2014
I have a little problem:
Код:
[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
command:
Код:
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;
}
What's wrong?