Uhrzeit ermitteln



  • Versuche schon eine Weile die aktuelle Uhrzeit zu ermitteln in Stunden und Minuten, scheint allerdings nicht zu klappen.

    time_t now;
    struct tm* tm;
    
    time(&now);
    tm = localtime(&now);
    

    Erhalte beim compilieren mit gcc folgenden Fehler:
    gerufenes Objekt »time« ist keine Funktion

    Was mache ich falsch? Bitte um Hilfe!



  • now = time(NULL);
    

    anstatt

    time(&now);
    

    und du musst wohl auch den benötigten Header noch einbinden.



  • Habe das geändert, auch <time.h> ist eingebunden.

    Bekomme leider immer noch denselben Fehler beim Compilieren. Irgendeine Idee?



  • Hi,

    feigling schrieb:

    now = time(NULL);
    

    anstatt

    time(&now);
    

    warum is doch egal wie er das macht:

    www.cplusplus.com schrieb:

    time_t time ( time_t * timer );

    <ctime>

    Get current time

    Get the current calendar time as a time_t object.

    The function returns this value, and if the argument is not a null pointer, the value is also set to the object pointed by timer.

    Parameters

    timer
    Pointer to an object of type time_t, where the time value is stored.
    Alternativelly, this parameter can be a null pointer, in which case the parameter is not used, but a time_t object is still returned by the function.

    Und wie schon gesagt halt

    #include <time.h>
    

    iwo schreiben, dann sollte alles ok sein.
    Post mal die genaue Fehlermeldung bzw deinen Code wenn er nicht so lang ist.

    Peace & Blessed Love C0de4Fun



  • So ist es auch möglich 😉

    #include <stdio.h>
    ...
    printf("Es sind %s Uhr",__TIME__);
    ...
    


  • Morgen,

    Andyman schrieb:

    So ist es auch möglich 😉

    #include <stdio.h>
    ...
    printf("Es sind %s Uhr",__TIME__);
    ...
    

    dir is aber schon bewusst das __TIME__ ein Macro ist!? Da es, wie schon gesagt, ein Macro ist wird es waehrend dem build Vorgang ausgewertet.
    Siehe auch:

    www.msdn.com schrieb:

    __TIME__

    The most recent compilation time of the current source file. The time is a string literal of the form hh🇲🇲ss.

    Peace & Blessed Love C0de4Fun



  • dir is aber schon bewusst das __TIME__ ein Macro ist!?

    Merkt man das nicht?



  • Andyman schrieb:

    printf("Es sind %s Uhr",__TIME__);
    

    mensch#1: weisst du wie spät es ist?
    mensch#2: ja, ich bin vorhin an 'ner uhr vorbeigekommen und hab's mir aufgeschrieben.
    🙂



  • fricky schrieb:

    mensch#1: weisst du wie spät es ist?
    mensch#2: ja, ich bin vorhin an 'ner uhr vorbeigekommen und hab's mir aufgeschrieben.

    Hehe. Wenn das so ist, schlage ich vor:

    printf("Es war %s Uhr",__TIME__);
    

    🙂



  • Programmiere noch nicht sehr lange und besitze daher noch ein kleines Grundwissen. Aber ich hoffe das wird sich in der nächsten Zeit noch ändern.
    Damit das passiert freue ich mich über jegliche Informationen 😃


Anmelden zum Antworten