SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 07/10/2012, 07:04 AM   #21
Jochemd
High-roller
 
Jochemd's Avatar
 
Join Date: Jul 2009
Location: The Netherlands
Posts: 2,220
Reputation: 844
Default Re: AW: TimestampToDate.inc - Convert a timestamp to a date!

Quote:
Originally Posted by s3rserii View Post
can u reupload the Example ?
I will when I get on my laptop.

Edit: Updated.
__________________

Last edited by Jochemd; 07/10/2012 at 08:18 AM.
Jochemd is offline   Reply With Quote
Old 07/10/2012, 09:21 AM   #22
s3rserii
Big Clucker
 
Join Date: Aug 2011
Posts: 52
Reputation: 0
Default AW: TimestampToDate.inc - Convert a timestamp to a date!

fine thx
s3rserii is offline   Reply With Quote
Old 03/12/2012, 11:47 AM   #23
Ballu Miaa
High-roller
 
Ballu Miaa's Avatar
 
Join Date: Apr 2010
Location: New Delhi,India
Posts: 1,849
Reputation: 323
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

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
__________________


I will take half payment as an advance to script for you.
Click here to request my Scripting Service.


Last edited by Ballu Miaa; 03/12/2012 at 04:21 PM.
Ballu Miaa is offline   Reply With Quote
Old 03/12/2012, 04:13 PM   #24
Ballu Miaa
High-roller
 
Ballu Miaa's Avatar
 
Join Date: Apr 2010
Location: New Delhi,India
Posts: 1,849
Reputation: 323
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

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 Code:
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 !!
Code:
[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 Code:
new ts = timestamp(),ts2 = gettime();
    printf("Current Time Stamp: %d and %d",ts,ts2);

The Output was:
Code:
 
[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 Code:
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;
}
__________________


I will take half payment as an advance to script for you.
Click here to request my Scripting Service.


Last edited by Ballu Miaa; 04/12/2012 at 04:15 AM.
Ballu Miaa is offline   Reply With Quote
Old 12/12/2012, 07:06 PM   #25
Jochemd
High-roller
 
Jochemd's Avatar
 
Join Date: Jul 2009
Location: The Netherlands
Posts: 2,220
Reputation: 844
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

Update 12/12/12 v1.2
Fixed Ballu Miaa's issue. Now 2 days are subtracted before even starting the loop.
__________________
Jochemd is offline   Reply With Quote
Old 13/12/2012, 02:08 AM   #26
Ballu Miaa
High-roller
 
Ballu Miaa's Avatar
 
Join Date: Apr 2010
Location: New Delhi,India
Posts: 1,849
Reputation: 323
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

Quote:
Originally Posted by Jochemd View Post
Update 12/12/12 v1.2
Fixed Ballu Miaa's issue. Now 2 days are subtracted before even starting the loop.
Haha Thanks bro!
__________________


I will take half payment as an advance to script for you.
Click here to request my Scripting Service.

Ballu Miaa is offline   Reply With Quote
Old 06/04/2013, 02:52 PM   #27
Jochemd
High-roller
 
Jochemd's Avatar
 
Join Date: Jul 2009
Location: The Netherlands
Posts: 2,220
Reputation: 844
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

UPDATE 06/04/2013: v2.0. This library contains a new stock: DateToTimestamp. I will explain this as well.
pawn Code:
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 Code:
new hello = DateToTimestamp("06.10.2013"); // 'hello' now contains 1381104000, which is correct for that day.
__________________
Jochemd is offline   Reply With Quote
Old 12/02/2014, 03:52 AM   #28
shaPP
Big Clucker
 
Join Date: Apr 2010
Posts: 70
Reputation: 3
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

I rly need this but i think it is a little bugged

Code:
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
shaPP is offline   Reply With Quote
Old 13/02/2014, 11:02 PM   #29
Drake1994
Big Clucker
 
Drake1994's Avatar
 
Join Date: Jun 2008
Posts: 111
Reputation: 54
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

Code:
TimestampToDate(bantime, y, m, d, y, m, s, 1);
instead use this:

Code:
TimestampToDate(bantime, y, m, d, h, mi, s, 1);
Drake1994 is offline   Reply With Quote
Old 14/02/2014, 03:35 AM   #30
shaPP
Big Clucker
 
Join Date: Apr 2010
Posts: 70
Reputation: 3
Default Re: TimestampToDate.inc - Convert a timestamp to a date!

OMFG didn't saw that little mistake ;d Thanks a lot :d gonna try it right now
shaPP is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a timestamp to countdown ThomasTailor93 Scripting Help 7 22/04/2012 02:39 PM
Unix timestamp to date/time function? Whizion Scripting Help 4 03/02/2012 07:01 AM
Unix timestamp for date format CyNiC Scripting Help 0 18/01/2012 12:33 PM
Is it possible to convert gettime() into Date and Time? Outbreak Help Archive 8 27/11/2009 11:32 PM


All times are GMT. The time now is 04:50 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.