<?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[Datum in String auffangen]]></title><description><![CDATA[<p>Ich habe folgende Funktion gefunden:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
#include &lt;time.h&gt;

void main()
{
    time_t Zeitstempel;
    tm *nun;
    Zeitstempel = time(0);
    nun = localtime(&amp;Zeitstempel);
    cout &lt;&lt; nun-&gt;tm_mday &lt;&lt; '.' &lt;&lt; nun-&gt;tm_mon+1 &lt;&lt; '.'
        &lt;&lt; nun-&gt;tm_year+1900 &lt;&lt; &quot; - &quot; &lt;&lt; nun-&gt;tm_hour
        &lt;&lt; ':' &lt;&lt; nun-&gt;tm_min &lt;&lt; endl;
}
</code></pre>
<p>Würde jetz aber gern statt der cout Anweisung einen String mit dem Datum belegen. Ist das möglich? bzw wie?<br />
Ich brauche das Datumsformat folgendermassen in dem String yyyymmdd hhmm</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/119761/datum-in-string-auffangen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 00:19:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/119761.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Sep 2005 11:07:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 11:07:03 GMT]]></title><description><![CDATA[<p>Ich habe folgende Funktion gefunden:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;
#include &lt;time.h&gt;

void main()
{
    time_t Zeitstempel;
    tm *nun;
    Zeitstempel = time(0);
    nun = localtime(&amp;Zeitstempel);
    cout &lt;&lt; nun-&gt;tm_mday &lt;&lt; '.' &lt;&lt; nun-&gt;tm_mon+1 &lt;&lt; '.'
        &lt;&lt; nun-&gt;tm_year+1900 &lt;&lt; &quot; - &quot; &lt;&lt; nun-&gt;tm_hour
        &lt;&lt; ':' &lt;&lt; nun-&gt;tm_min &lt;&lt; endl;
}
</code></pre>
<p>Würde jetz aber gern statt der cout Anweisung einen String mit dem Datum belegen. Ist das möglich? bzw wie?<br />
Ich brauche das Datumsformat folgendermassen in dem String yyyymmdd hhmm</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865306</guid><dc:creator><![CDATA[Nicor]]></dc:creator><pubDate>Mon, 05 Sep 2005 11:07:03 GMT</pubDate></item><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 11:25:43 GMT]]></title><description><![CDATA[<p>Wenn es sich bei den Datentypen (sorry, keine Ahnung, was es für Datentypen in tm sind) um Strings handelt, könntest du sie einfach zusammen in einen mit strcpy(); oder strcat(); schreiben, ansonsten würde ich eine Konvertierung zu char [] oder string vornehmen und sie dann auf einen einzelnen String umkopieren.</p>
<p>habs getestet, die Datentypen sind int bei den Zahlen.<br />
Von daher konvertieren in char und mittels strcpy/strcat in ein char-Array kopieren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865318</guid><dc:creator><![CDATA[Vorden]]></dc:creator><pubDate>Mon, 05 Sep 2005 11:25:43 GMT</pubDate></item><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 11:25:12 GMT]]></title><description><![CDATA[<p>time.h schrieb:</p>
<blockquote>
<pre><code class="language-cpp">struct tm
{
  int tm_sec;                   /* Seconds.     [0-60] (1 leap second) */
  int tm_min;                   /* Minutes.     [0-59] */
  int tm_hour;                  /* Hours.       [0-23] */
  int tm_mday;                  /* Day.         [1-31] */
  int tm_mon;                   /* Month.       [0-11] */
  int tm_year;                  /* Year - 1900.  */
  int tm_wday;                  /* Day of week. [0-6] */
  int tm_yday;                  /* Days in year.[0-365] */
  int tm_isdst;                 /* DST.         [-1/0/1]*/

#ifdef  __USE_BSD
  long int tm_gmtoff;           /* Seconds east of UTC.  */
  __const char *tm_zone;        /* Timezone abbreviation.  */
#else
  long int __tm_gmtoff;         /* Seconds east of UTC.  */
  __const char *__tm_zone;      /* Timezone abbreviation.  */
#endif
};
</code></pre>
</blockquote>
<p>es handelt sich also um ints<br />
naja man könnte in char* konvertieren(zB über nen stringstream) und denn einfach zu einem string mittels += hinzufügen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865322</guid><dc:creator><![CDATA[shapeless]]></dc:creator><pubDate>Mon, 05 Sep 2005 11:25:12 GMT</pubDate></item><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 11:29:56 GMT]]></title><description><![CDATA[<p>Vorden schrieb:</p>
<blockquote>
<p>Wenn es sich bei den Datentypen (sorry, keine Ahnung, was es für Datentypen in tm sind) um Strings handelt, könntest du sie einfach zusammen in einen mit strcpy(); oder strcat(); schreiben, ansonsten würde ich eine Konvertierung zu char [] oder string vornehmen und sie dann auf einen einzelnen String umkopieren.</p>
</blockquote>
<p>Warum so kompliziert?</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10266">@Nicor</a>:</p>
<p>1. bzg. <a href="http://fara.cs.uni-potsdam.de/~kaufmann/?page=GenCppFaqs&amp;faq=main#Answ" rel="nofollow">void main()</a></p>
<p>2. Wie wärs mit stringstreams?<br />
Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;sstream&gt; // Der header ist neu.
#include &lt;ctime&gt;
using namespace std;

int main()
{
    time_t Zeitstempel;
    tm *nun;
    Zeitstempel = time(0);
    nun = localtime(&amp;Zeitstempel);

    // erzeuge ein ostringstream objekt.
    ostringstream ostream;

    // schreibe alles in den buffer von ostream.
    ostream &lt;&lt; nun-&gt;tm_mday &lt;&lt; '.' &lt;&lt; nun-&gt;tm_mon+1 &lt;&lt; '.'
        &lt;&lt; nun-&gt;tm_year+1900 &lt;&lt; &quot; - &quot; &lt;&lt; nun-&gt;tm_hour
        &lt;&lt; ':' &lt;&lt; nun-&gt;tm_min;

    // konvertiere den kompletten Inhalt (der z.Z. im buffer von ostream steht)
    // nach std::string    
    string s = ostream.str();
    cout &lt;&lt; &quot;\n s: &quot; &lt;&lt; s &lt;&lt; &quot;\n\n&quot;;
    return 0;
}
</code></pre>
<p>/edit: zu spät...</p>
<p>Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865326</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865326</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Mon, 05 Sep 2005 11:29:56 GMT</pubDate></item><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 11:33:39 GMT]]></title><description><![CDATA[<p>Es handelt sich eigentlich um eine C-Frage, ich denke, das einfachste waere wenn Du die strftime-Funktion benutzen wuerdest (eine aehnliche Frage war unlaengst im ANSI-C-Forum);</p>
<pre><code class="language-cpp">char   szTimeStr [100]; /* 100 sollte hier vollkommen ausreichen */

    time_t Zeitstempel;
    tm *nun;
    Zeitstempel = time(0);
    nun = localtime(&amp;Zeitstempel);

    strftime(szTimeStr, 100, ... /* Formatstring: selber definieren - s.u. */, 
                               nun);
    cout &lt;&lt; szTimeStr;
</code></pre>
<p>Fuer den Formatstring solltest Du entweder den ANSi-Standard oder ein anderes C-Referenzbuch heranziehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865331</guid><dc:creator><![CDATA[MBCS-CITP]]></dc:creator><pubDate>Mon, 05 Sep 2005 11:33:39 GMT</pubDate></item><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 11:35:06 GMT]]></title><description><![CDATA[<p>MBCS-CITP schrieb:</p>
<blockquote>
<p>Es handelt sich eigentlich um eine C-Frage, ich denke, das einfachste waere wenn Du die strftime-Funktion benutzen wuerdest (eine aehnliche Frage war unlaengst im ANSI-C-Forum);</p>
<pre><code class="language-cpp">char   szTimeStr [100]; /* 100 sollte hier vollkommen ausreichen */

    time_t Zeitstempel;
    tm *nun;
    Zeitstempel = time(0);
    nun = localtime(&amp;Zeitstempel);

    strftime(szTimeStr, 100, ... /* Formatstring: selber definieren - s.u. */, 
                               nun);
    cout &lt;&lt; szTimeStr;
</code></pre>
<p>Fuer den Formatstring solltest Du entweder den ANSi-Standard oder ein anderes C-Referenzbuch heranziehen.</p>
</blockquote>
<p>Seit wann benutzt man in C cout ? Hab da in C eher was von printf gehört ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865333</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865333</guid><dc:creator><![CDATA[Vorden]]></dc:creator><pubDate>Mon, 05 Sep 2005 11:35:06 GMT</pubDate></item><item><title><![CDATA[Reply to Datum in String auffangen on Mon, 05 Sep 2005 13:58:36 GMT]]></title><description><![CDATA[<p>Nein, aber aber, da er offensichlich mit Streams arbeiten will, habe ich cout benutzt. Ich persoenlich haette - auch in C++ - ein printf hingeschmiert. Aber ich will jetzt keine Diskussion uber das Fuer und Wieder der stdio.h vs. iostream starten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/865451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/865451</guid><dc:creator><![CDATA[MBCS-CITP]]></dc:creator><pubDate>Mon, 05 Sep 2005 13:58:36 GMT</pubDate></item></channel></rss>