Timestamp



  • Nun, möchte mich schonmal für die viele Hilfe bedanken, aber was noch nett wäre:
    Wenn nun in meinem Proggie wirklich mal eine updated Seite vorgefunden wird, dann möchte ich gerne abgesehen von Alarmglocken noch eine Zeitangabe über cout ausgeben.. ich kenn zwar die Funktion mit der man einen 64 bit Wert kriegt, der der aktuellen Systemzeit entspricht.. aber wie krieg ich das in ein string und user freundliches Format z.B.: "12:24"..? Datum wäre auch nett 😉



  • schlimmstenfalls, indem du den Timestamp Stück für Stück auseinanderbröselst 😉



  • umm?!? wie das?
    der Rückgabewert von der Funktion dessen Namen ich nicht mehr weiss is ungefähr sowas:
    1354635676478356735676376576357
    und das sind noch nicht mal millisekunden, denn jeder PC erhöht den Counter anders, abhängig von der CPU..



  • der nachfolgende code holt die aktuelle systemzeit und packt sie in das struct
    room in std::string gDate

    is also das was du suchst oder
    das format des strings sieht so aus

    Tue Jul 26 17:47:16 2005

    time_t rawtime;
       time ( &rawtime );
      room.gDATE     = ctime (&rawtime);
      room.gDATE[24] = 0x00;
    


  • Im C++-Standard gibt es eine Facette 'time_put', die für die Formatierung von Zeit zuständigt ist. Anbei ein Beispiel wie man das verwendet.

    #include <iostream>
    #include <locale>
    #include <ctime>       // struct std::tm, usw.
    
    // -- Zeit-struct std::tm ausgeben
    std::ostream& operator<<( std::ostream& out, const std::tm& time )
    {
        using namespace std;
        const std::time_put< char > &tp = 
            std::use_facet< std::time_put< char > >( std::locale("") );
    
        const char tmFormat[] = "%H:%M:%S"; // <-- hier Format einstellen
        const char* tmFormatEnd = tmFormat + sizeof(tmFormat) - 1;
        tp.put( std::ostreambuf_iterator< char >( out ), out, out.fill(), &time, tmFormat, tmFormatEnd );
        return out;
    }
    
    // -- Manipulator zur Ausgabe der aktuellen Zeit
    std::ostream& current_time( std::ostream& out )
    {
        using namespace std;
        time_t dummy = {0};
        time_t now_ = time( &dummy );
        const tm now = *localtime( &now_ );
        return out << now;
    }
    
    int main()
    {
        using namespace std;
        cout << current_time << endl;
        return 0;
    }
    

    Mehr Info dazu gibt's hier http://www.roguewave.com/support/docs/sourcepro/stdlibref/time-put.html
    Gruß
    Werner


Anmelden zum Antworten