<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[mktime() bzw difftime() geht nicht]]></title><description><![CDATA[<p>Hallo Zusammen,<br />
ich programmiere gerade an einem Programm, indem ich ein Datum einlese und von diesem Datum aus die Anzahl der Tage bis heute berechnen moechte. Mein Gedanke war es dieses Problem mit mktime() und difftime zu loesen. Leider zeigt mir die variable t immer 0 an. Kann mir bitte jemand weiterhelfen? Ich bin auch offen fuer eine bessere Loesung. Danke</p>
<pre><code>struct tm *timeinfo;
	struct tm *timeinfo2;
	time_t rawtime;

	time(&amp;rawtime);
	timeinfo = localtime(&amp;rawtime);
	timeinfo2 = localtime(&amp;rawtime);

	timeinfo-&gt;tm_year =2014-1900;
	timeinfo-&gt;tm_mon =11;
	timeinfo-&gt;tm_mday =21;

	timeinfo2-&gt;tm_year =2013-1900;
	timeinfo2-&gt;tm_mon =11;
	timeinfo2-&gt;tm_mday =25;
	timeinfo2-&gt;tm_min=1;

	double t=difftime(mktime(timeinfo2),mktime(timeinfo));[code]
</code></pre>
<p>[/code]</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/322088/mktime-bzw-difftime-geht-nicht</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 10:10:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322088.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Dec 2013 01:25:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to mktime() bzw difftime() geht nicht on Fri, 06 Dec 2013 01:25:42 GMT]]></title><description><![CDATA[<p>Hallo Zusammen,<br />
ich programmiere gerade an einem Programm, indem ich ein Datum einlese und von diesem Datum aus die Anzahl der Tage bis heute berechnen moechte. Mein Gedanke war es dieses Problem mit mktime() und difftime zu loesen. Leider zeigt mir die variable t immer 0 an. Kann mir bitte jemand weiterhelfen? Ich bin auch offen fuer eine bessere Loesung. Danke</p>
<pre><code>struct tm *timeinfo;
	struct tm *timeinfo2;
	time_t rawtime;

	time(&amp;rawtime);
	timeinfo = localtime(&amp;rawtime);
	timeinfo2 = localtime(&amp;rawtime);

	timeinfo-&gt;tm_year =2014-1900;
	timeinfo-&gt;tm_mon =11;
	timeinfo-&gt;tm_mday =21;

	timeinfo2-&gt;tm_year =2013-1900;
	timeinfo2-&gt;tm_mon =11;
	timeinfo2-&gt;tm_mday =25;
	timeinfo2-&gt;tm_min=1;

	double t=difftime(mktime(timeinfo2),mktime(timeinfo));[code]
</code></pre>
<p>[/code]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370107</guid><dc:creator><![CDATA[CppChina]]></dc:creator><pubDate>Fri, 06 Dec 2013 01:25:42 GMT</pubDate></item><item><title><![CDATA[Reply to mktime() bzw difftime() geht nicht on Fri, 06 Dec 2013 07:45:07 GMT]]></title><description><![CDATA[<p>Warum benutzt du hier localtime?</p>
<p>localtime schrieb:</p>
<blockquote>
<p>Return Value<br />
A pointer to a tm structure with its members filled with the values that correspond to the local time representation of timer.</p>
<p>The returned value points to an internal object whose validity or value may be altered by any subsequent call to gmtime or localtime.</p>
</blockquote>
<p><a href="http://www.cplusplus.com/reference/ctime/localtime/" rel="nofollow">http://www.cplusplus.com/reference/ctime/localtime/</a></p>
<p>Du kannst ja mal in Zeile 8 ein</p>
<pre><code>printf(&quot;%p %p %i\n&quot;, timeinfo, timeinfo2, timeinfo-timeinfo2);
</code></pre>
<p>einfügen.<br />
Dann siehst du, das die structs die selbe Adresse haben.</p>
<p>Also nimm richtige <code>struct tm</code> und nicht nur Pointer.<br />
Und <code>localtime_s</code> , wenn es das auf deinem System gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370124</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 06 Dec 2013 07:45:07 GMT</pubDate></item><item><title><![CDATA[Reply to mktime() bzw difftime() geht nicht on Mon, 09 Dec 2013 02:49:18 GMT]]></title><description><![CDATA[<p>Es funktioniert immer noch nicht. Ich sitze immer noch auf dem Schlauch. ich habe den Code wie folgt veraendert, jedoch hat sich nichts geandert. kann jemand bitte meinen Code anpassen bzw. mir sagen was ich aendern soll. Vielen Dank</p>
<pre><code>struct tm timeinfo,timeinfo2;
	time_t rawtime;

	time(&amp;rawtime);
	localtime_s(&amp;timeinfo,&amp;rawtime);
	localtime_s(&amp;timeinfo,&amp;rawtime);

	timeinfo.tm_year =2014-1900;
	timeinfo.tm_mon =11;
	timeinfo.tm_mday =21;

	timeinfo2.tm_year =2013-1900;
	timeinfo2.tm_mon =11;
	timeinfo2.tm_mday =25;
	timeinfo2.tm_min=1;

	double t=difftime(mktime(&amp;timeinfo2),mktime(&amp;timeinfo));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2370651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370651</guid><dc:creator><![CDATA[CppChina]]></dc:creator><pubDate>Mon, 09 Dec 2013 02:49:18 GMT</pubDate></item><item><title><![CDATA[Reply to mktime() bzw difftime() geht nicht on Mon, 09 Dec 2013 03:11:03 GMT]]></title><description><![CDATA[<p>Jetzt funktioniert es. Es war noch einer Fehler enthalten. Rueckgabe ist die Differenz in Sekunden.</p>
<pre><code>struct tm timeinfo,timeinfo2;
	time_t rawtime;

	//time(&amp;rawtime);
	localtime_s(&amp;timeinfo,&amp;rawtime);
	localtime_s(&amp;timeinfo2,&amp;rawtime);

	timeinfo.tm_year =2013-1900;
	timeinfo.tm_mon =11;
	timeinfo.tm_mday =21;

	timeinfo2.tm_year =2013-1900;
	timeinfo2.tm_mon =11;
	timeinfo2.tm_mday =25;

	double t=difftime(mktime(&amp;timeinfo2),mktime(&amp;timeinfo));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2370652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370652</guid><dc:creator><![CDATA[CppChina]]></dc:creator><pubDate>Mon, 09 Dec 2013 03:11:03 GMT</pubDate></item></channel></rss>