SA-MP Forums Archive
Unix Timestamp Decode/Encode? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Unix Timestamp Decode/Encode? (/showthread.php?tid=255976)



Unix Timestamp Decode/Encode? - Cody09 - 18.05.2011

Hi all,

I have a problem,

I know to encode the Timestamp in Pawn:
Код HTML:
gettime();
So, but I want to decode the Timestamp, so a function for pawn like:

decode_timestamp(timestamp,&second,&minute,&hour,& day,&month,&year)
{
//here I donґt know what to insert
}

Iґll hope you can help me

MfG. Cody09


Re: Unix Timestamp Decode/Encode? - playbox12 - 18.05.2011

pawn Код:
new Hour, Minute, Second, Year, Month, Day;
gettime(Hour, Minute, Second);
getdate(Year, Month, Day);



AW: Unix Timestamp Decode/Encode? - Cody09 - 18.05.2011

no, I want to decode my timestamp


Re: Unix Timestamp Decode/Encode? - __ - 18.05.2011

Read the tutorial in my signature. You will need to use a custom function entitled "mktime" which I copied a link to in my tutorial topic.


AW: Unix Timestamp Decode/Encode? - Cody09 - 18.05.2011

Can someone make me the custom function^^, I donґt find any link? Only a link to the 2038 Problem, and a link to the temporary vip


Re: Unix Timestamp Decode/Encode? - __ - 18.05.2011

pawn Код:
stock mktime(hour, minute, second, day, month, year)
{
    static
        days_of_month[12] =
        {
            31,
            29,
            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;
}
stock mktime(hour, minute, second, day, month, year)
{
    static
        days_of_month[12] =
        {
            31,
            29,
            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;
}
There's the function.


AW: Unix Timestamp Decode/Encode? - Cody09 - 18.05.2011

but I need a function to make the timestamp to a date in fomat: sec,min,hour,day,moth,year