SA-MP Forums Archive
Timestamp... - 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)
+--- Thread: Timestamp... (/showthread.php?tid=558635)



Timestamp... - Baltimore - 18.01.2015

Hello!

Do you have a function that converts a timestamp to a string? (Day, month, year, hour, minute, second)

Thank you.


Re: Timestamp... - ATGOggy - 18.01.2015

You can make a custom function:
PHP код:
stock TimeStamp()
{
    new 
timestamp[128], daymonthyearhourminutesecond;
    
getdate(year,month,day);
    
gettimer(hour,minute,second);
    
format(timestampsizeof(timestamp), "%d:%d:%d, %d:%d:%d"daymonthyearhourminutesecond);
    return 
timestamp;




Re : Re: Timestamp... - Baltimore - 18.01.2015

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
You can make a custom function:
PHP код:
stock TimeStamp()
{
    new 
timestamp[128], daymonthyearhourminutesecond;
    
getdate(year,month,day);
    
gettimer(hour,minute,second);
    
format(timestampsizeof(timestamp), "%d:%d:%d, %d:%d:%d"daymonthyearhourminutesecond);
    return 
timestamp;

I want a "dynamic" function, I get the timestamp parameter of the function, and it then leaves me the string as given above (day, month, year, hour, minute, second)


Re: Timestamp... - xVIP3Rx - 18.01.2015

You already made this post,
Quote:
Originally Posted by ******
Посмотреть сообщение
Believe me, it isn't. You need to account for:

Timezones.
Leap years (i.e. leap days).
Leap seconds (of which there is one due soon).
Daylight savings (which can change with no notice).
Formats (dd/mm/yy vs mm/dd/yy etc).

If you want this function, you need to be VASTLY more precise about exactly what you want, because there is no single representation of time.



Re: Timestamp... - RedFusion - 18.01.2015

pawn Код:
timestamp(&year, &month, &day, &hour, &minute, &second)
{
    new
        string[20]
    ;

    getdate(year, month, day);
    gettime(hour, minute, second);

    format(string, sizeof string, "%i-%02i-%02i %02i:%02i:%02i",
        year, month, day, hour, minute, second
    );

    return string;
}



Re : Re: Timestamp... - Baltimore - 18.01.2015

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
pawn Код:
timestamp(&year, &month, &day, &hour, &minute, &second)
{
    new
        timestamp[20]
    ;

    getdate(year, month, day);
    gettime(hour, minute, second);

    format(timestamp, sizeof timestamp, "%i-%02i-%02i %02i:%02i:%02i",
        year, month, day, hour, minute, second
    );

    return timestamp;
}
I want to get the timestamp parameter of the function, there is time and everything directly ...


Re: Timestamp... - RedFusion - 18.01.2015

pawn Код:
timestamp(&year, &month, &day, &hour, &minute, &second, string[], string_size = sizeof string)
{
    getdate(year, month, day);
    gettime(hour, minute, second);

    format(string, string_size, "%i-%02i-%02i %02i:%02i:%02i",
        year, month, day, hour, minute, second
    );
}



Re : Re: Timestamp... - Baltimore - 18.01.2015

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
pawn Код:
timestamp(&year, &month, &day, &hour, &minute, &second, string[], string_size = sizeof string)
{
    getdate(year, month, day);
    gettime(hour, minute, second);

    format(string, string_size, "%i-%02i-%02i %02i:%02i:%02i",
        year, month, day, hour, minute, second
    );
}
Exemple for use this code please...

I have only the timestamp, so I do not see how I could fill the parameters hours, day.. To the function


Re: Timestamp... - tyler12 - 18.01.2015

https://sampforum.blast.hk/showthread.php?tid=347605


Re: Timestamp... - RedFusion - 18.01.2015

Example Usage:
pawn Код:
public OnFilterScriptInit()
{
    new
        year,
        month,
        day,
        hour,
        minute,
        second,
        string[20]
    ;
   
    timestamp(year, month, day, hour, minute, second, string);

    printf("Timestamp: %s", string);
    printf("Year: %i", year);
    printf("Month: %i", month);
    printf("Day: %i", day);
    printf("Hour: %i", hour);
    printf("Minute: %i", minute);
    printf("Second: %i", second);
}