<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Linux vs. _strdate _strtime</title>
		<link>http://www.allegro.cc/forums/view/593088</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 09 Sep 2007 09:44:20 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve been using _strdate/_strtime (I include &lt;time.h&gt; of course) in my program to get the date/time (it&#39;s nice for the high scores you know) ... it seems to work in windows even with the allegro timer installed.  Which is awesome.</p><p>When I go to compile on debian linux however I get &quot;_strdate was not declared in this scope&quot; along with &quot;_strtime was not declared in this scope&quot; -- are there some other functions I should be using instead for linux?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Fri, 07 Sep 2007 13:13:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, one thing to note, all symbols that start with an underscore are reserved symbols <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> Somehow MS missed that...</p><p>Anyhow, _foo functions in windows are typically just renamed versions of the standard libc methods. Though those functions don&#39;t even seem to exist in libc. try <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_760.html" target="_blank">strftime</a>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_127.html" target="_blank">ctime</a>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_45.html" target="_blank">asctime</a> <span class="k1">or</span> strptime</span> instead.</p><p>note, the first three are c89 and c99 (and another), while the latter is only SUSv2, and POSIX.1-2001.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 07 Sep 2007 13:18:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">char</span> str<span class="k2">[</span><span class="n">32</span><span class="k2">]</span><span class="k2">;</span> <span class="c">/* Will hold the string for the current date/time; must be at least 26 bytes */</span>
ctime_r<span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span>, str<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
The normal <tt>ctime</tt> function is C89, but is not reentrant. It&#39;s returned string may be overwritten on subsequent calls. <tt>ctime_r</tt> is safer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Fri, 07 Sep 2007 13:21:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Personally, I&#39;d use strftime. Much safer, and you can easily specify the format.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 07 Sep 2007 13:24:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>google code search is a badass:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">char</span> cptime<span class="k2">[</span><span class="n">50</span><span class="k2">]</span><span class="k2">;</span> <span class="c">//char ptr</span></td></tr><tr><td class="number">2</td><td>string GetDate<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">3</td><td><span class="k2">{</span></td></tr><tr><td class="number">4</td><td>  time_t now<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>  now <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span><span class="k2">(</span>time_t<span class="k3">*</span><span class="k2">)</span>NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>  <span class="c">//time(&amp;now); // shouldn't be needed right?</span></td></tr><tr><td class="number">7</td><td>  <span class="k1">struct</span> tm <span class="k3">*</span>l_time <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_538.html" target="_blank">localtime</a><span class="k2">(</span><span class="k3">&amp;</span>now<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>cptime, <span class="s">"%.2d/%.2d/%.4d"</span>, l_time-&gt;tm_mon, l_time-&gt;tm_mday, l_time-&gt;tm_year <span class="k3">+</span> <span class="n">1900</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>  string strTime <span class="k3">=</span> cptime<span class="k2">;</span></td></tr><tr><td class="number">10</td><td>  <span class="k1">return</span> strTime<span class="k2">;</span></td></tr><tr><td class="number">11</td><td><span class="k2">}</span></td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td>string GetTime<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">14</td><td><span class="k2">{</span></td></tr><tr><td class="number">15</td><td>  time_t now<span class="k2">;</span></td></tr><tr><td class="number">16</td><td>  now <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span><span class="k2">(</span>time_t<span class="k3">*</span><span class="k2">)</span>NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>  <span class="c">//time(&amp;now); // shouldn't be needed right?</span></td></tr><tr><td class="number">18</td><td>  <span class="k1">struct</span> tm <span class="k3">*</span>l_time <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_538.html" target="_blank">localtime</a><span class="k2">(</span><span class="k3">&amp;</span>now<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>cptime, <span class="s">"%.2d:%.2d:%.2d"</span>, l_time-&gt;tm_hour, l_time-&gt;tm_min, l_time-&gt;tm_sec<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>  string strTime <span class="k3">=</span> cptime<span class="k2">;</span></td></tr><tr><td class="number">21</td><td>  <span class="k1">return</span> strTime<span class="k2">;</span></td></tr><tr><td class="number">22</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
<a href="http://www.google.com/codesearch?hl=en&amp;q=+_strdate+show:LLwPyRUKVrg:7SkldA23HA0:SMESY5bMXVg&amp;sa=N&amp;cd=5&amp;ct=rc&amp;cs_p=http://standards.iso.org/ittf/PubliclyAvailableStandards/c041955_ISO_IEC_14496-5_2001_Amd_8_Reference_Software.zip&amp;cs_f=ISO_IEC_14496-5_2001_Amd_8_Reference_Software/VIDEO/NATURAL/JM_10_1/LENCOD/SRC/LENCOD.C#a0">I have no idea what this is for, but I got most of that code from analyzing this</a></p><p>It works in msvc/gcc on windows, I just have to upload and try it on linux.</p><p>Thanks for the input guys, it DID help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Fri, 07 Sep 2007 13:38:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">char</span> buf<span class="k2">[</span><span class="n">100</span><span class="k2">]</span><span class="k2">;</span>
<span class="c">/* Print today's date e.g. "January 31, 2001".  */</span>
time_t mytime <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.delorie.com/djgpp/doc/libc/libc_760.html" target="_blank">strftime</a> <span class="k2">(</span>buf, <span class="n">100</span>, <span class="s">"%B %d, %Y"</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_538.html" target="_blank">localtime</a><span class="k2">(</span><span class="k3">&amp;</span>mytime<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
string strTime <span class="k3">=</span> buf<span class="k2">;</span>
</pre></div></div><p>

<img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 07 Sep 2007 13:53:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>but I... I don&#39;t want that format...</p><p>however: localtime(time) seems like a neat way access the time... but... dont you have to call localtime(time(NULL)) or at least localtime(time())?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Fri, 07 Sep 2007 13:55:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
however: localtime(time) seems like a neat way access the time... but... dont you have to call localtime(time(NULL)) or at least localtime(time())?
</p></div></div><p>I made a couple mistakes* <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />  and the &quot;format&quot; can be anything, seeing as its a FORMAT <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> (forinstance, see the %D and %T format items)</p><ul><li><p>see my edit <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></li></ul></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 07 Sep 2007 14:00:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>so my current code now is:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">char</span> cptime<span class="k2">[</span><span class="n">50</span><span class="k2">]</span><span class="k2">;</span> <span class="c">//char ptr</span></td></tr><tr><td class="number">2</td><td>string GetDate<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">3</td><td><span class="k2">{</span></td></tr><tr><td class="number">4</td><td>  time_t now <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">5</td><td>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_760.html" target="_blank">strftime</a><span class="k2">(</span>cptime, <span class="n">50</span>, <span class="s">"%b. %d, %Y"</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_538.html" target="_blank">localtime</a><span class="k2">(</span><span class="k3">&amp;</span>now<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//uses short month name</span></td></tr><tr><td class="number">6</td><td>  string strTime <span class="k3">=</span> cptime<span class="k2">;</span></td></tr><tr><td class="number">7</td><td>  <span class="k1">return</span> strTime<span class="k2">;</span></td></tr><tr><td class="number">8</td><td><span class="k2">}</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>string GetTime<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">11</td><td><span class="k2">{</span></td></tr><tr><td class="number">12</td><td>  time_t now <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_760.html" target="_blank">strftime</a><span class="k2">(</span>cptime, <span class="n">50</span>, <span class="s">"%I:%M %p"</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_538.html" target="_blank">localtime</a><span class="k2">(</span><span class="k3">&amp;</span>now<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>  string strTime <span class="k3">=</span> cptime<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>  <span class="k1">return</span> strTime<span class="k2">;</span></td></tr><tr><td class="number">16</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Fri, 07 Sep 2007 14:15:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could just &quot;return string(cptime);&quot; to shorten it by another line of code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 07 Sep 2007 18:14:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or just return cptime and let the compiler convert.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Fri, 07 Sep 2007 20:31:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>dunno what cptime is or how it&#39;s formatted, but this is working in msvc/mingw/linux-g++ so I&#39;m happy. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Fri, 07 Sep 2007 23:19:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>cptime is your variable <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> sheesh man.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 08 Sep 2007 02:09:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>oh, so it is. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Sun, 09 Sep 2007 09:44:20 +0000</pubDate>
	</item>
</rss>
