[Include] TimestampToDate.inc - Convert a timestamp to a date!
#24

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;
}
Reply


Messages In This Thread
TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 02.06.2012, 14:27
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 02.06.2012, 15:33
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 02.06.2012, 19:41
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Kyle - 02.06.2012, 23:50
Re: TimestampToDate.inc - Convert a timestamp to a date! - by IceCube! - 03.06.2012, 00:12
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 03.06.2012, 08:35
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Niko_boy - 03.06.2012, 10:16
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 03.06.2012, 10:21
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 03.06.2012, 10:43
Re: TimestampToDate.inc - Convert a timestamp to a date! - by legodude - 03.06.2012, 12:49
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 03.06.2012, 12:49
Re: TimestampToDate.inc - Convert a timestamp to a date! - by legodude - 03.06.2012, 12:57
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Kyle - 04.06.2012, 22:18
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Lorenc_ - 05.06.2012, 05:46
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 05.06.2012, 10:12
Re: TimestampToDate.inc - Convert a timestamp to a date! - by mick88 - 05.06.2012, 13:13
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 07.06.2012, 09:08
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Hanger - 07.06.2012, 20:23
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 13.06.2012, 10:19
AW: TimestampToDate.inc - Convert a timestamp to a date! - by s3rserii - 06.10.2012, 09:03
Re: AW: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 07.10.2012, 07:04
AW: TimestampToDate.inc - Convert a timestamp to a date! - by s3rserii - 07.10.2012, 09:21
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Ballu Miaa - 03.12.2012, 11:47
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Ballu Miaa - 03.12.2012, 16:13
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 12.12.2012, 19:06
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Ballu Miaa - 13.12.2012, 02:08
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 06.04.2013, 14:52
Re: TimestampToDate.inc - Convert a timestamp to a date! - by shaPP - 12.02.2014, 03:52
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Drake1994 - 13.02.2014, 23:02
Re: TimestampToDate.inc - Convert a timestamp to a date! - by shaPP - 14.02.2014, 03:35
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 30.03.2014, 12:22
Respuesta: TimestampToDate.inc - Convert a timestamp to a date! - by MugiwaraNoLuffy - 31.03.2014, 05:21
Re: Respuesta: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 31.03.2014, 13:00
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Zio - 06.04.2014, 23:15
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 08.04.2014, 15:02
Respuesta: Re: Respuesta: TimestampToDate.inc - Convert a timestamp to a date! - by MugiwaraNoLuffy - 09.04.2014, 17:30
Respuesta: Re: TimestampToDate.inc - Convert a timestamp to a date! - by MugiwaraNoLuffy - 10.04.2014, 03:37
Re: TimestampToDate.inc - Convert a timestamp to a date! - by sammp - 30.06.2014, 21:54
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 30.06.2014, 22:11
Re: TimestampToDate.inc - Convert a timestamp to a date! - by PapaSmerf - 24.07.2014, 19:01
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 25.07.2014, 09:25
Re: TimestampToDate.inc - Convert a timestamp to a date! - by PapaSmerf - 25.07.2014, 11:51
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 25.07.2014, 12:46
Re: TimestampToDate.inc - Convert a timestamp to a date! - by dominik523 - 05.12.2014, 20:09
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 07.12.2014, 10:20
Re: TimestampToDate.inc - Convert a timestamp to a date! - by dominik523 - 07.12.2014, 17:23
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 07.12.2014, 19:44
Re: TimestampToDate.inc - Convert a timestamp to a date! - by dominik523 - 07.12.2014, 20:25
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 07.12.2014, 20:44
Re: TimestampToDate.inc - Convert a timestamp to a date! - by dominik523 - 07.12.2014, 21:19
Re : TimestampToDate.inc - Convert a timestamp to a date! - by Baltimore - 27.12.2014, 22:41
Re : TimestampToDate.inc - Convert a timestamp to a date! - by Baltimore - 28.12.2014, 03:19
Re: Re : TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 28.12.2014, 15:59
Re: TimestampToDate.inc - Convert a timestamp to a date! - by DetoNater - 23.06.2015, 08:28
Re: TimestampToDate.inc - Convert a timestamp to a date! - by darkowner - 23.06.2015, 09:39
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 23.06.2015, 20:32
Re: TimestampToDate.inc - Convert a timestamp to a date! - by TenTen - 07.07.2015, 21:05
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Crayder - 19.10.2015, 06:26
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 19.10.2015, 06:59
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Redirect Left - 17.11.2015, 16:26
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Firerfan - 29.12.2015, 20:22
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jeffry - 29.11.2016, 17:47
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Shetch - 29.01.2017, 00:11
Re: TimestampToDate.inc - Convert a timestamp to a date! - by MerryDeer - 29.01.2017, 08:02
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 04.02.2017, 15:14
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Kwarde - 23.12.2017, 01:15
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Jochemd - 29.12.2017, 09:50
Re: TimestampToDate.inc - Convert a timestamp to a date! - by Kwarde - 29.12.2017, 10:46

Forum Jump:


Users browsing this thread: 11 Guest(s)