<?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[Zeit schreiben und wieder auslesen]]></title><description><![CDATA[<p>Ich habe ein Programm, das die momentane Systemzeit in ein Textdokument &quot;data.txt&quot; schreibt.</p>
<pre><code>#include &lt;fstream&gt;
#include &lt;chrono&gt;
#include &lt;ctime&gt;
#include &lt;string&gt;

using namespace std;
typedef chrono::system_clock Clock;

int main() {

Clock::time_point now = Clock::now();
time_t tOutput = Clock::to_time_t(now);
fstream file(&quot;data.txt&quot;, ios::out);
char* output = ctime(&amp;tOutput);
file &lt;&lt; endl &lt;&lt; output;
flush(file);
file.close();
}
</code></pre>
<p>data.txt.<br />
Wed Jul 06 14:46:43 2016</p>
<p>Nun möchte ich diese Zeit wieder in time_t konvertieren. Eingelesen habe ich die Zeit schon als</p>
<pre><code>char* time
</code></pre>
<p>. Gibt es da irgendeine einfache Möglichkeit?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/338735/zeit-schreiben-und-wieder-auslesen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 08:41:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338735.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jul 2016 14:23:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeit schreiben und wieder auslesen on Wed, 06 Jul 2016 14:23:40 GMT]]></title><description><![CDATA[<p>Ich habe ein Programm, das die momentane Systemzeit in ein Textdokument &quot;data.txt&quot; schreibt.</p>
<pre><code>#include &lt;fstream&gt;
#include &lt;chrono&gt;
#include &lt;ctime&gt;
#include &lt;string&gt;

using namespace std;
typedef chrono::system_clock Clock;

int main() {

Clock::time_point now = Clock::now();
time_t tOutput = Clock::to_time_t(now);
fstream file(&quot;data.txt&quot;, ios::out);
char* output = ctime(&amp;tOutput);
file &lt;&lt; endl &lt;&lt; output;
flush(file);
file.close();
}
</code></pre>
<p>data.txt.<br />
Wed Jul 06 14:46:43 2016</p>
<p>Nun möchte ich diese Zeit wieder in time_t konvertieren. Eingelesen habe ich die Zeit schon als</p>
<pre><code>char* time
</code></pre>
<p>. Gibt es da irgendeine einfache Möglichkeit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501422</guid><dc:creator><![CDATA[Shedex]]></dc:creator><pubDate>Wed, 06 Jul 2016 14:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to Zeit schreiben und wieder auslesen on Wed, 06 Jul 2016 15:16:04 GMT]]></title><description><![CDATA[<p>Hallo Shedex,</p>
<p>Willkomme im C++-Forum.</p>
<p>Für das Schreiben und Lesen von Datum und Uhrzeit gibt es die Manipulatoren put_- und get_time.<br />
Anbei ein Beispiel:</p>
<pre><code>#include &lt;fstream&gt;
#include &lt;chrono&gt;
#include &lt;ctime&gt;    // std::tm, localtime
#include &lt;iomanip&gt;  // std::put_time, get_time
#include &lt;iostream&gt; // cerr, cout, etc.

typedef std::chrono::system_clock Clock;

int main() {
    using namespace std;
    //                  Wed Jul 06 16:42:10 2016
    const char* format = &quot;%a %b %d %H:%M:%S %Y&quot;;
    Clock::time_point now = Clock::now();
    time_t now_time_t = Clock::to_time_t(now);
    {
        ofstream file(&quot;data.txt&quot;);
        file &lt;&lt; put_time( localtime( &amp;now_time_t ), format ) &lt;&lt; endl;
    }   // } -&gt; file -&gt; flush&amp;close

    cout &lt;&lt; &quot;Bitte einen Moment warten und dann 'return' druecken &gt;&quot;;
    cin.get();

    {
        ifstream file_in(&quot;data.txt&quot;);
        if( !file_in.is_open() )
        {
            cerr &lt;&lt; &quot;Fehler beim Oeffnen der Datei&quot; &lt;&lt; endl;
            return 0;
        }
        tm aTime;
        if( file_in &gt;&gt; get_time( &amp;aTime, format ) )
        {
            auto vorher = Clock::from_time_t( mktime( &amp;aTime ) );
            cout &lt;&lt; &quot;Seit dem Schreiben sind &quot; &lt;&lt; chrono::duration_cast&lt; chrono::seconds &gt;(Clock::now() - vorher).count() &lt;&lt; &quot;s vergangen&quot; &lt;&lt; endl;
        }
    }
    return 0;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501427</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 06 Jul 2016 15:16:04 GMT</pubDate></item></channel></rss>