Timestamp...
#1

Hello!

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

Thank you.
Reply
#2

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;

Reply
#3

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)
Reply
#4

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

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

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

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
    );
}
Reply
#8

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

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

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);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)