View Full Version : FormatTime()
Is there a list of valid time formats for format time?
http://www.amxmodx.org/funcwiki.php?go=func&id=249
Try that since I'm pretty sure it was just an amxx port
BAILOPAN
08-14-2007, 23:17
http://www.php.net/strftime same parameters as this.
Rasmus4J
07-11-2009, 17:03
Hi,
I'm really new at SourcePAwn (actually just started today),
and i've encountered a problem with the FormatTime command.
this is my entire script
/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
public Plugin:myinfo =
{
name = "Test coding skills",
author = "CA | Ramsus [DK]",
description = "This is my first SourcePawn script, to test my skills",
version = "1.0.0",
url = "0"
}
public OnPluginStart()
{
RegConsoleCmd("say", Command_Say)
}
public Action:Command_Say(client, args)
{
new String:text[192]
GetCmdArgString(text, sizeof(text))
new startidx = 0
if (text[0] == '"')
{
startidx = 1
/* strip the ending quote, if there is one */
new len = strlen(text);
if (text[len-1] == '"')
{
text[len-1] = '\0'
}
}
if (StrEqual(text[startidx], "ffire"))
{
new Handle:ffire = FindConVar("mp_friendlyfire")
if (GetConVarInt(ffire))
{
PrintToChat(client, "Friendly fire is active");
}
else
{
PrintToChat(client, "Friendly fire is not active");
}
/* Block the client's messsage from broadcasting */
return Plugin_Handled
}
if (StrEqual(text[startidx], "timenow"))
{
new String:time[512], Handle:TimeTmp = GetTime();
FormatTime(time, sizeof(time), "%I:%M:%S", TimeTmp);
PrintToChat(client, "the time is %d now", time);
return Plugin_Handled
}
/* Let say continue normally */
return Plugin_Continue
}but the problem is, as you might have found out, in this part:
if (StrEqual(text[startidx], "timenow"))
{
new String:time[512], Handle:TimeTmp = GetTime();
FormatTime(time, sizeof(time), "%I:%M:%S", TimeTmp);
PrintToChat(client, "the time is %d now", time);
return Plugin_Handled
}it does display a message in the chat, but it doesn't format the time, it just gives me a time stamp,
the message looks like this: "the time is 893005873 now", which it shouldn't according to my needs and hopes.
I have tried doing this:
if (StrEqual(text[startidx], "timenow"))
{
new String:time[512]
FormatTime(time, sizeof(time), "%I:%M:%S", GetTime());
PrintToChat(client, "the time is %d now", time);
return Plugin_Handled
}instead, but it gives the same result.
Can anyone help me getting a real time ? (btw. this is non-american).
Kind regards
Rasmus
Your time output is a string so use %s instead of %d:
PrintToChat(client, "the time is %s now", time);
Rasmus4J
07-11-2009, 17:16
Your time output is a string so use %s instead of %d:
PrintToChat(client, "the time is %s now", time);
you're kidding me right? is that my problem :S
and btw. what can i do about tag mismatch in this line: new String:time[512], Handle:TimeTmp = GetTime();
GetTime() returns not a handle, it is an integer value (number of seconds since 1970). :)
Rasmus4J
07-11-2009, 17:25
so i should remove the handle part and actually just move it down in the formattime command, as the stamp ?
and how do i make it 24 hour clock instead of 12 hour ?
Something like this...
decl String:szTime[30];
FormatTime(szTime, sizeof(szTime), "%H:%M:%S", GetTime());
PrintToChat(client, "The time is %s now", szTime);
so i should remove the handle part and actually just move it down in the formattime command, as the stamp ?
yeap
Rasmus4J
07-11-2009, 17:41
Something like this...
decl String:szTime[30];
FormatTime(szTime, sizeof(szTime), "%H:%M:%S", GetTime());
PrintToChat(client, "The time is %s now", szTime);
yeap
Thank you so much! :) don't know why it suddenly became 24 hour clock just by the var and such, but it is.
but can you explain why it became 24 hour clock so that I learn more than "just do it this way" but so that I actually know why :)
You are welcome. I've just changed (http://www.php.net/strftime) %I to %H.
Rasmus4J
07-11-2009, 18:05
LOL :P i don't know why %I was there in the first place ? Thought I had used %H :P
well, thanks again :)
Gave you some Karma for the nice treatment and responses:)
Hello, I'm having also problems with thetime command.
I've changed in sourcemod.cfg to:
sm_datetime_format "%d.m%.%Y - %H:%M:%S"and in-game "thetime" is NOT working. But if it is:
sm_datetime_format "%d/m%/%Y - %H:%M:%S"It's working. Or if it is the default, again working.
Maybe it can't recognize dot "." ? Because I don't want to be with "/".
Maybe I have to change something in basetriggers.sp:
else if (strcmp(text[startidx], "thetime", false) == 0)
{
decl String:ctime[64];
FormatTime(ctime, 64, NULL_STRING);
if(GetConVarInt(g_Cvar_TriggerShow))
{
PrintToChatAll("[SM] %t", "Thetime", ctime);
}
else
{
PrintToChat(client,"[SM] %t", "Thetime", ctime);
}
}To work ?
Yep, it works, 10x. This is my second "poor sight/бедные прицел" :P.
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.