26.07.2015, 20:27
Alguйm por acaso sabe algum cуdigo que converte informaзхes de gettime() em data e hora?? Ficarei grato se alguйm tiver o mesmo.
// Convert UNIX time to human readable time
stock convertTimestamp( timestamp, _form=0 )
{
timestamp -= 10800;
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] = {"Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"};
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, hour++;
}
sec=timestamp;
switch( _form ){
case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour, 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);
case 4: format(returnstring, 31, "%02d.%02d.%d-%02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
default: format(returnstring, 31, "%02d:%02d:%02d %02d/%02d/%d", hour, mins, sec, day+1, month+1, year);
}
return returnstring;
}
public OnPlayerConnect(playerid) {new strTime[32], boasvindas[128]; GetDateFromTime(gettime(), strTime); format(boasvindas, 128, "Olб, seja bem vindo, a data de hoje й %s!", strTime); SendClientMessage(playerid, -1, boasvindas); return 1;} stock GetDateFromTime(timestamp, string[32]) { new tm <tmStamp>; localtime(Time:timestamp, tmStamp); strftime(string, sizeof(string), "%d/%m/%y", tmStamp); //retorna dd/mm/aaaa return 1; }
GetDateFromTime(timestamp, string[32])
{
new tm <tmStamp>;
localtime(Time:timestamp, tmStamp);
strftime(string, sizeof(string), "%d/%m/%Y - %H:%M:%S", tmStamp); //retorna dd/mm/aaaa
return 1;
}
static vString[32];
GetDateFromTime(APlayerData[playerid][pExpira] - gettime(), vString);
format(tString, sizeof(tString), "SERVER: Vocк й um Player %s, o mesmo expira em %s.", RankVIP(APlayerData[playerid][pVIP]), vString);
Eu dei uma modificada no seu cуdigo Leon, ficou assim:
pawn Code:
pawn Code:
|
#define DaysToSeconds(%0) (%0 * 86400) |
#define DaysToSeconds(%0) (%0 * 86400) APlayerData[playerid][pExpira] = gettime() + DaysToSeconds(30);