Unix Timestamp Decode/Encode?
#1

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
Reply
#2

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

no, I want to decode my timestamp
Reply
#4

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.
Reply
#5

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
Reply
#6

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.
Reply
#7

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


Forum Jump:


Users browsing this thread: 1 Guest(s)