Uhrzeit anzeigen



  • Wie kann ich in einem Programm die aktuelle Zeit ausgeben ?



  • Hallo,

    schau dir mal die Funktionen 'time' und 'ctime' an. (Definiert in time.h)

    Das sollte dir weiterhelfen.

    mfg
    v R



  • ähm, bin n Neuling was programmieren angeht, wie schau ich denn was in einer Bibliothek nach ?



  • ähhm in dem du dir ne Doku besorgst.
    Oder du schaust dir bloß den Header an. Wo deine Header liegen weiss ich nich aber das Verzeichnis des Compilers bzw. ein Unterverzeichnis, dass meistens include heist ist ein guter Ansatz. Unter unix schau mal unter /usr/include.
    Und wenn du alles haben willst musst du dir die Source der lib besorgen.

    Aba ich denke es reicht völlig (in deinem Fall) mal nach time.h zu googln oder eben in den Header zu schaun.



  • Falls du keine Doku hast (schnell besorgen):

    Header File

    time.h

    Category

    Time and Date Routines

    Prototype

    time_t time(time_t *timer);

    Description

    Gets time of day.

    time gives the current time, in seconds, elapsed since 00:00:00 GMT, January 1, 1970, and stores that value in the location pointed to by timer, provided that timer is not a NULL pointer.

    Return Value

    time returns the elapsed time in seconds.

    Und

    Header File

    time.h

    Category

    Time and Date Routines

    Prototype

    char *ctime(const time_t *time);

    wchar_t *_wctime(const time_t *time);

    Description

    Converts date and time to a string.

    ctime converts a time value pointed to by time (the value returned by the function time) into a 26-character string in the following form, terminating with a newline character and a null character:

    Mon Nov 21 11:31:54 1983\n\0

    All the fields have constant width.

    The global long variable _timezone contains the difference in seconds between GMT and local standard time (in PST, _timezone
    is 8*60*60). The global variable _daylight is used to tell the RTL's functions (mktime & localtime) whether they should take daylight saving time into account if it runs into a date that would normally fall into that category. It is set to 1 if the daylight savings time conversion should be applied.. These variables are set by the tzset function, not by the user program directly.

    Return Value

    ctime returns a pointer to the character string containing the date and time. The return value points to static data that is overwritten with each call to ctime.

    Auszuege aus der Borland Doku.

    mfg
    v R



  • probiers mal damit:

    #include <stdio.h>
    #include <time.h>
    
    int main(void) 
    { 
    	struct tm *newtime;
        time_t long_time;
    
        time( &long_time );                // Get time as long integer.
        newtime = localtime( &long_time ); // Convert to local time.
    
        printf("Uhrzeit = %d:%d:%d", newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
    
    	return 0;
    }
    

Anmelden zum Antworten