05.01.2014, 20:08
Title basically says it all, could I define like a second, minute, hour, day, month, year, etc? Then somehow incorporate that into a command that shows the date? Any help would be appreciated.
stock GetTodaysDate()
{
new
dString[ 18+2 ],
Date[ 6 ]
;
//Year //Month //Day
getdate(Date[ 0 ], Date[ 1 ], Date[ 2 ]);
//Hour //Minutes //Seconds
gettime(Date[ 3 ], Date[ 4 ], Date[ 5 ]);
format(dString, sizeof (dString), "%d/%d/%d %d:%d:%d", Date[ 2 ], Date[ 1 ], Date[ 0 ], Date[ 3 ], Date[ 4 ], Date[ 5 ]);
return dString;
}
Kind of like this, but how could I make this right here into a /time command using ZCMD?
|
CMD:time(playerid, params[])
{
new string[ 30 ], Date[ 6 ]
;
//Year //Month //Day
getdate(Date[ 0 ], Date[ 1 ], Date[ 2 ]);
//Hour //Minutes //Seconds
gettime(Date[ 3 ], Date[ 4 ], Date[ 5 ]);
format( string, sizeof( string ), "Todays Time: %i:%i", Date[3], Date[4]), SendClientMessage( playerid, -1, string );
format( string, sizeof( string ), "Todays Date: %i:%i:%i", Date[ 0 ], Date[ 1 ], Date[ 2 ]), SendClientMessage( playerid, -1, string );
return true;
}
This should work.
pawn Код:
|
Works perfectly, thanks man! One question though, is it possible for it to display the time like how for me right now it's 3:41 P.M. versus displaying it as 15:41 P.M.? So I guess what I mean is is there a way to have it print like 3:41 P.M. or if it was 3:41 A.M. it could detect that, too?
|
CMD:time(playerid, params[])
{
new string[ 30 ], Date[ 7 ]
;
//Year //Month //Day
getdate(Date[ 0 ], Date[ 1 ], Date[ 2 ]);
//Hour //Minutes //Seconds
gettime(Date[ 3 ], Date[ 4 ], Date[ 5 ]);
format( string, sizeof( string ), "Todays Date: %i:%i:%i", Date[ 0 ], Date[ 1 ], Date[ 2 ]), SendClientMessage( playerid, -1, string );
if(Date[ 3 ] >= 12 && Date[ 4 ] > 0)
{
Date [ 6 ] = Date[ 3 ] - 12;
format( string, sizeof( string ), "Todays Time: %i:%i PM", Date[ 6 ], Date[ 4 ]), SendClientMessage( playerid, -1, string );
}
else if(Date[ 3 ] < 12 && Date[ 4 ] > 0)
{
format( string, sizeof( string ), "Todays Time: %i:%i AM", Date[ 3 ], Date[ 4 ]), SendClientMessage( playerid, -1, string );
}
return true;
}
pawn Код:
EDIT: Modified PDS2k12's code a little |
CMD:time(playerid, params[])
{
new string[ 30 ], Date[ 6 ]
;
//Year //Month //Day
getdate(Date[ 0 ], Date[ 1 ], Date[ 2 ]);
//Hour //Minutes //Seconds
gettime(Date[ 3 ], Date[ 4 ], Date[ 5 ]);
format( string, sizeof( string ), "Todays Date: %i:%i:%i", Date[ 0 ], Date[ 1 ], Date[ 2 ]), SendClientMessage( playerid, -1, string );
format( string, sizeof( string ), "Todays Time: %i:%i AM", Date[ 3 ]%12, Date[ 4 ]), SendClientMessage( playerid, -1, string );
return true;
}
A more compact version:
pawn Код:
|