SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/01/2020, 07:30 PM   #1
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 312
Reputation: 8
Default TimestampToDate

pawn Code:
new string[20], time[6];
TimestampToDate((3*3600),time[0],time[1],time[2],time[3],time[4],time[5],0);
format(string, sizeof(string), "Date: %d-%d-%d Time: %d:%d", time[2], time[1], time[0], time[3], time[4]);
Code:
Output: Date: -1--1-1970 Time: 1:0
Where am I wrong?
I want return date and time (Time after 3 hours).
Vizi10 is offline   Reply With Quote
Old 28/01/2020, 07:35 PM   #2
Shamans
Little Clucker
 
Shamans's Avatar
 
Join Date: Oct 2019
Posts: 12
Reputation: 0
Default Re: TimestampToDate

What is the server time that may be different from Unix?
Shamans is offline   Reply With Quote
Old 28/01/2020, 07:54 PM   #3
Radless
Little Clucker
 
Join Date: Jul 2019
Posts: 40
Reputation: 3
Default Re: TimestampToDate

Code:
stock getDate(timestamp, _form = 0)
{
    new year=1970, day=0, month=0, hour=0, mins=0, sec=0;

    new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    new names_of_month[12][10] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
    new returnstring[36];

    while (timestamp>31622400)
	{
        timestamp -= 31536000;
        if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
        year++;
    }

    if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
        days_of_month[1] = 29;
    else
        days_of_month[1] = 28;


    while (timestamp>86400)
	{
        timestamp -= 86400, day++;
        if (day==days_of_month[month]) day=0, month++;
    }

    while (timestamp>60)
	{
        timestamp -= 60, mins++;
        if ( mins == 60) mins=0, hour++;
    }

    sec=timestamp;

    switch ( _form )
	{
        case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour+3, mins, sec);
        case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour+3, mins, sec);
        case 3: format(returnstring, 31, "%d %c%c%c %d, %02d:%02d", day+1,names_of_month[month][0],names_of_month[month][1],names_of_month[month][2], year,hour+3,mins);

        default: format(returnstring, 31, "%02d.%02d.%d - %02d:%02d:%02d", day+1, month+1, year, hour+3, mins, sec);
    }

    return returnstring;
}
Example usage:

Code:
printf("%s", getDate(gettime()));
Radless 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
TimestampToDate EvgeniyHostel1992 Scripting Help 4 04/03/2018 08:21 AM
timestamptodate.inc Error OPTILEX Scripting Help 7 26/11/2017 07:22 AM
TimestampToDate returns an extra day Riwerry Scripting Help 1 26/06/2017 12:04 PM
[Ajuda] TimestampToDate.inc CaioTJF Português/Portuguese 3 09/11/2016 12:51 AM
Can someone give me the TimestampToDate.inc ? EgyptForLife Scripting Help 2 21/05/2014 02:08 PM


All times are GMT. The time now is 11:30 AM.


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