<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to use Time and Date in C</title>
	<atom:link href="http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c</link>
	<description>CodingUnit is your online resource for learning to program. Tutorials on C, C++, PHP, Python, MySQL, Java, JQuery, Opengl, DirectX and much more!</description>
	<lastBuildDate>Thu, 29 Jul 2010 15:47:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-1074</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 29 Jun 2010 17:47:11 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-1074</guid>
		<description>@Sanket
It all depends what you are trying to do. For example do you need precision or is an approximation alright.
For more precision you can find tools like &lt;a href=&quot;http://www.code-wizards.com/projects/libfaketime/index.html&quot; rel=&quot;nofollow&quot;&gt;libfaketime&lt;/a&gt; online. (On the site you also find the source code of the faketime library.)

For an approximation result, you can use something like the example below:
(note: just a quick and dirty example, no error checking, etc)

#include &lt;stdio.h&gt;
#include &lt;time.h&gt;


void wait ( int sec ) {
	int a =0;
	clock_t end_wait;
	end_wait = clock () + sec * CLK_TCK;
	while (clock() &lt; end_wait) {

		// Your useless calculations.
		a++;
	}
	printf (&quot;%i\n&quot;, a);
}

void waitspeedup ( int sec, int speedupfactor ) {
	int num,a = 0;
	num = sec / speedupfactor;
	printf (&quot;The new wait time is: %i\n&quot;, num);
	clock_t end_wait;
	end_wait = clock () + num * CLK_TCK;
	while (clock() &lt; end_wait) {

		// Your useless calculations
		a++;
	}
	// The fake result (because of speedup factor)
	printf (&quot;%i\n&quot;, a);
	// Multiply result with speedupfactor to get an approximation
	// of the actual results.
	printf (&quot;%i\n&quot;, a*speedupfactor);
}

int main () {
	printf (&quot;Waiting.1....\n&quot;);
	// Wait approx. 12 seconds
	wait(12);
	printf (&quot;Waiting.2....\n&quot;);
	// Wait approx. 12 / 2 = 6 seconds
	waitspeedup(12,2);
	// There are 86400 seconds in a day
	// do something like this 86400/1200=72 sec.
	return 0;
}

Hope that this is useful for you. Good luck!</description>
		<content:encoded><![CDATA[<p>@Sanket<br />
It all depends what you are trying to do. For example do you need precision or is an approximation alright.<br />
For more precision you can find tools like <a href="http://www.code-wizards.com/projects/libfaketime/index.html" rel="nofollow">libfaketime</a> online. (On the site you also find the source code of the faketime library.)</p>
<p>For an approximation result, you can use something like the example below:<br />
(note: just a quick and dirty example, no error checking, etc)</p>
<p>#include &lt;stdio.h&gt;<br />
#include &lt;time.h&gt;</p>
<p>void wait ( int sec ) {<br />
	int a =0;<br />
	clock_t end_wait;<br />
	end_wait = clock () + sec * CLK_TCK;<br />
	while (clock() &lt; end_wait) {</p>
<p>		// Your useless calculations.<br />
		a++;<br />
	}<br />
	printf (&#8220;%i\n&#8221;, a);<br />
}</p>
<p>void waitspeedup ( int sec, int speedupfactor ) {<br />
	int num,a = 0;<br />
	num = sec / speedupfactor;<br />
	printf (&#8220;The new wait time is: %i\n&#8221;, num);<br />
	clock_t end_wait;<br />
	end_wait = clock () + num * CLK_TCK;<br />
	while (clock() &lt; end_wait) {</p>
<p>		// Your useless calculations<br />
		a++;<br />
	}<br />
	// The fake result (because of speedup factor)<br />
	printf (&#8220;%i\n&#8221;, a);<br />
	// Multiply result with speedupfactor to get an approximation<br />
	// of the actual results.<br />
	printf (&#8220;%i\n&#8221;, a*speedupfactor);<br />
}</p>
<p>int main () {<br />
	printf (&#8220;Waiting.1&#8230;.\n&#8221;);<br />
	// Wait approx. 12 seconds<br />
	wait(12);<br />
	printf (&#8220;Waiting.2&#8230;.\n&#8221;);<br />
	// Wait approx. 12 / 2 = 6 seconds<br />
	waitspeedup(12,2);<br />
	// There are 86400 seconds in a day<br />
	// do something like this 86400/1200=72 sec.<br />
	return 0;<br />
}</p>
<p>Hope that this is useful for you. Good luck!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanket</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-1006</link>
		<dc:creator>Sanket</dc:creator>
		<pubDate>Fri, 25 Jun 2010 09:32:20 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-1006</guid>
		<description>Hello,

I was going through your site and found it quite interesting.

I have a question.....

I would like to measure 24 hrs on my machine without waiting for 24 hrs...... is it possible ? (By making some useless calculation in loop).

Could you provide me with an example.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I was going through your site and found it quite interesting.</p>
<p>I have a question&#8230;..</p>
<p>I would like to measure 24 hrs on my machine without waiting for 24 hrs&#8230;&#8230; is it possible ? (By making some useless calculation in loop).</p>
<p>Could you provide me with an example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alfred Tebbs</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-922</link>
		<dc:creator>Alfred Tebbs</dc:creator>
		<pubDate>Fri, 09 Apr 2010 15:56:18 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-922</guid>
		<description>I was reading your blog and thought i would say hi.</description>
		<content:encoded><![CDATA[<p>I was reading your blog and thought i would say hi.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-624</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 03 Feb 2010 16:58:13 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-624</guid>
		<description>As promised in the previous comment, we have&lt;a href=&quot;http://www.codingunit.com/how-to-make-a-calendar-in-c&quot; rel=&quot;nofollow&quot;&gt; created a calendar tutorial that you can find here&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>As promised in the previous comment, we have<a href="http://www.codingunit.com/how-to-make-a-calendar-in-c" rel="nofollow"> created a calendar tutorial that you can find here</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-547</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 01 Feb 2010 21:16:35 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-547</guid>
		<description>Don&#039;t exactly know what your question is, but I think your question is: you have a current date. What is the date of the next day? 

If this is your question, then the simple answer is +1. 

The hard answer is: you have to take the number of days of the month your into account. You also have to make sure it&#039;s not a leap year (see note.) So your calculation get harder.

Note: a leap year does not strictly fall on every fourth year.  If a year is divisible by 4, then it is a leap year, but if that year is divisible by 100, then it is not a leap year.  However, if the year is also divisible by 400, then it is a leap year. 

The leap year calculation can be done like so:

&lt;code&gt;
int leap_year (int year)
{
   if(year% 4==0 &amp;&amp; year%100 != 0 &#124;&#124; year%400==0)
   return TRUE;
   else return FALSE;	
}
&lt;/code&gt;

The best thing you can do is to create a calendar function for yourself. If I have some time tomorrow I will post a example.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t exactly know what your question is, but I think your question is: you have a current date. What is the date of the next day? </p>
<p>If this is your question, then the simple answer is +1. </p>
<p>The hard answer is: you have to take the number of days of the month your into account. You also have to make sure it&#8217;s not a leap year (see note.) So your calculation get harder.</p>
<p>Note: a leap year does not strictly fall on every fourth year.  If a year is divisible by 4, then it is a leap year, but if that year is divisible by 100, then it is not a leap year.  However, if the year is also divisible by 400, then it is a leap year. </p>
<p>The leap year calculation can be done like so:</p>
<p><code><br />
int leap_year (int year)<br />
{<br />
   if(year% 4==0 &#038;&#038; year%100 != 0 || year%400==0)<br />
   return TRUE;<br />
   else return FALSE;<br />
}<br />
</code></p>
<p>The best thing you can do is to create a calendar function for yourself. If I have some time tomorrow I will post a example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joemar asiado</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-521</link>
		<dc:creator>joemar asiado</dc:creator>
		<pubDate>Mon, 01 Feb 2010 08:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-521</guid>
		<description>current date:


following date:???????</description>
		<content:encoded><![CDATA[<p>current date:</p>
<p>following date:???????</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-546</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sun, 10 Jan 2010 20:50:50 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-546</guid>
		<description>I don&#039;t know exactly what your question is but the function time() can be used if you include time.h on Unix systems and the function will return the type time_t. Hope it answers your question.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know exactly what your question is but the function time() can be used if you include time.h on Unix systems and the function will return the type time_t. Hope it answers your question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Salim</title>
		<link>http://www.codingunit.com/c-tutorial-how-to-use-time-and-date-in-c/comment-page-1#comment-198</link>
		<dc:creator>Salim</dc:creator>
		<pubDate>Fri, 08 Jan 2010 12:20:34 +0000</pubDate>
		<guid isPermaLink="false">http://localhost/?p=228#comment-198</guid>
		<description>Thanks for sharing but I have problem to enter different date and time value from the computer date and time. I could not find where time(); function is defined.</description>
		<content:encoded><![CDATA[<p>Thanks for sharing but I have problem to enter different date and time value from the computer date and time. I could not find where time(); function is defined.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
