Raised This Month: $32 Target: $400
 8% 

Time formats available to windows?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 16:27   Time formats available to windows?
Reply With Quote #1

I am wondering which time formats are available for windows. I am using the following code to get the 2-digit number for the month:

Code:
new String:formattedMonth[2];
		FormatTime(formattedMonth, sizeof(formattedMonth), "%m");
I got my formats from here. This works great on my test server (on a linux machine), however, the server the plugin is for is on windows, and generates this error:

Code:
L 02/19/2014 - 15:06:08: [SM] Native "FormatTime" reported: Invalid time format or buffer too small
L 02/19/2014 - 15:06:08: [SM] Displaying call stack trace for plugin "plugin-name.smx":
L 02/19/2014 - 15:06:08: [SM]   [0]  Line 386, C:\scripting-file-path\plugin-name.smx::OnMapEnd()
I found this thread that states that some of those formats dont work on windows machines. So, I am wondering (after having searched around long enough -.-) if there is a list elsewhere for the ones available on windows.

Ultimately, I am just using it for a time stamp in a file name. This is the code I am using (which, again, works great for my linux test server, but wont generate the file on my windows machine). The debug you see in the coding does fire, so the issue is purely in the filename not being able to use that format.

Spoiler


Originally, I used %F instead of %m and %d, but the above code was an attempt to get it working on the windows machine. Additionally, the string lengths were originally longer (much more than needed), but I put it to these shorter lengths (the exact length it will use) to see if that did anything.

I imagine there is a simpler way to add the date stamp as I want it, but I am newer to coding, so I wasnt sure which way would be best. From what I understand, this is simply an OS issue with regards to accepted formats of FormatTime.

Any help is much appreciated. Thanks!
ThatOneGuy is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-19-2014 , 16:47   Re: Time formats available to windows?
Reply With Quote #2

PHP Code:
new String:formattedMonth[2]; 
buffer too small.
5 Strings
It include NULL ternimator.
So
PHP Code:
new String:formattedMonth[3]; 
*edit
PHP Code:
"%m" output is "02" 

Last edited by Bacardi; 02-19-2014 at 16:48.
Bacardi is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 16:50   Re: Time formats available to windows?
Reply With Quote #3

I originally had it set to 60 though...ill try 3 and get back tya though.
ThatOneGuy is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 16:55   Re: Time formats available to windows?
Reply With Quote #4

ok...so now it just generates the error for the %R format...which maybe that one isnt for windows...ill try converting it to lower case equivalents.
ThatOneGuy is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 17:04   Re: Time formats available to windows?
Reply With Quote #5

Additionally, is there a simple way to combine all the time/date strings into one, rather than replace multiple tags? Like could I do this: (I'm guessing no)

Code:
new String:formattedMonth[3];
FormatTime(formattedMonth, sizeof(formattedMonth), "%m");
new String:formattedDay[3];
FormatTime(formattedDay, sizeof(formattedDay), "%d");
new String:formattedTime[6];
FormatTime(formattedTime, sizeof(formattedTime), "%R");

//is this a valid line below?
new String:formattedtag[30] = ("%s/%s "%s", formattedMonth, formattedDay, formattedTime);

new String:sumpath[250] = "addons/sourcemod/logs/plugin-folder/mappopsummary_<tag>.log";
ReplaceString(sumpath, sizeof(sumpath), "<tag>", formattedtag);
So to ask such basic questions, but you have to learn somehow, eh?

Last edited by ThatOneGuy; 02-19-2014 at 17:04.
ThatOneGuy is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 17:15   Re: Time formats available to windows?
Reply With Quote #6

Using the lower case equivelents worked...I guess the windows machine didnt like the %R format.

The code I ended with:

Spoiler


Thanks for pointing out the null terminator to me (I had forgotten about that). Turned out to be a format issue with windows after all : /

Note: The %H and %M are used in what is written in the file...just in case you noticed they arent used in what i posted above

---------------------------------

Also, as stated in the OP, if anyone knows of a list of formats applicable to windows OS, please post.

-ToG

Last edited by ThatOneGuy; 02-19-2014 at 17:20.
ThatOneGuy is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 02-19-2014 , 17:21   Re: Time formats available to windows?
Reply With Quote #7

Consolidate specifiers, use Format once, don't use three quotation marks on the same line, don't use a slash for your filename (or any other symbols - keep it simple), and ReplaceString is unneeded.

Edit: Some of these are fixed in that post above now. And since you asked: http://www.cplusplus.com/reference/ctime/strftime/

This should be fine:

PHP Code:
new String:sumpath[PLATFORM_MAX_PATH];
FormatTime(sumpathsizeof(sumpath), "addons/sourcemod/logs/plugin-folder/mappopsummary_%m-%d.log"); 
__________________

Last edited by 11530; 02-19-2014 at 17:28.
11530 is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 17:31   Re: Time formats available to windows?
Reply With Quote #8

Quote:
Originally Posted by 11530 View Post
Consolidate specifiers
Not sure what you mean by that

Quote:
Originally Posted by 11530 View Post
use Format once
How so? All the formats that combine those do not work on windows...

Quote:
Originally Posted by 11530 View Post
don't use three quotation marks on the same line
Not sure what youre referring to there...

Quote:
Originally Posted by 11530 View Post
don't use a slash for your filename
I dont?...not sure where you see a slash outside of the directories.
Quote:
Originally Posted by 11530 View Post
I gave that exact same link in my OP...please read more carefully as to why that is NOT what I was looking for (that one lists many that are N/A to windows.

Thanks for the reply though...
ThatOneGuy is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 02-19-2014 , 17:33   Re: Time formats available to windows?
Reply With Quote #9

Quote:
Originally Posted by 11530 View Post
This should be fine:

PHP Code:
new String:sumpath[PLATFORM_MAX_PATH];
FormatTime(sumpathsizeof(sumpath), "addons/sourcemod/logs/plugin-folder/mappopsummary_%m-%d.log"); 
Ok...thanks for editing your post...I didnt know I could put the path right in the formattime line. That looks MUCH cleaner!

Last edited by ThatOneGuy; 02-19-2014 at 17:33.
ThatOneGuy is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-19-2014 , 17:38   Re: Time formats available to windows?
Reply With Quote #10

use also buildpath, to rigth SourceMod folder if you run forked server.
PHP Code:
    new String:buffer[PLATFORM_MAX_PATH];
    
FormatTime(buffersizeof(buffer), "mappopsummary_%m-%d.log");
    
BuildPath(Path_SMbuffersizeof(buffer), "logs/plugin-folder/%s"buffer);
    
PrintToServer("buffer =%s"buffer); // look output 

Last edited by Bacardi; 02-19-2014 at 17:39.
Bacardi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode