Using a timestamp for this...
#1

It has been awhile since I did anything in PAWN and have forgotten how to use timestamps, sort of.

I am trying to display the date/time of someone being banned, as well as when they will be unbanned. This is part of my current code:

pawn Код:
new szString[128];
            SendClientMessage(playerid, COLOR_RED, "You are banned from this server.");
            SendClientMessage(playerid, -1, " ");
            format(szString, sizeof(szString), "You were banned by {E70000}%s {FFFFFF}on %s.", szAdminName, szBanDateTime);
            SendClientMessage(playerid, COLOR_WHITE, szString);
            format(szString, sizeof(szString), "You will be automatically unbanned on {E70000}%s{FFFFFF}.", szUnbanDateTime);
            SendClientMessage(playerid, COLOR_WHITE, szString);
            Kick(playerid);
I want to display the date/time strings like this: "Sunday, January 1, 2013 14:00"

I have taken a look at CTime by RyDeR`, but I got a bit confused.

Can anyone help?
Reply
#2

Why don't you use this?

pawn Код:
stock date( timestamp, _form=0 )
{
    /*
        ~ convert a Timestamp to a Date.
        ~ 10.07.2009

        date( 1247182451 )  will print >> 09.07.2009-23:34:11
        date( 1247182451, 1) will print >> 09/07/2009, 23:34:11
        date( 1247182451, 2) will print >> July 09, 2009, 23:34:11
        date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
    */

    new year=1970, day=0, month=0, hours=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[32];

    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, hours++;
    }

    sec=timestamp;

    switch( _form ){
        case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hours, mins, sec);
        case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hours, 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,mins);

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

    return returnstring;
}
Reply
#3

... that was the damn function I was looking for.

Does somebody have a gun I can use to shoot myself? ... J/K

Thanks, Dokins!
Reply
#4

Ahaha!

Don't mention it.

I'm Grant, I just use this account for the fun of it.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
Really? Loops to do a division operation?
How would you do it, ******?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)