請問使用C++語言如何讀取系統日期及時間

請問使用C++語言如何讀取系統日期及時間,日期包含禮拜幾...謝謝各位大大解答

3 Answers

Rating
  • 2 decades ago
    Favorite Answer

    Header File

    time.h

    Category

    Time and Date Routines

    Prototype

    struct tm *gmtime(const time_t *timer);

    Description

    Converts date and time to Greenwich mean time (GMT).

    gmtime accepts the address of a value returned by time and returns a pointer to the structure of type tm containing the time elements. gmtime converts directly to GMT.

    The global long variable _timezone should be set to the difference in seconds between GMT and local standard time (in PST _timezone is 8 x 60 x 60). The global variable _daylight should be set to nonzero only if the standard U.S. daylight saving time conversion should be applied.

    This is the tm structure declaration from the time.h header file:

    struct tm {

    int tm_sec; /* Seconds */

    int tm_min; /* Minutes */

    int tm_hour; /* Hour (0 - 23) */

    int tm_mday; /* Day of month (1 - 31) */

    int tm_mon; /* Month (0 - 11) */

    int tm_year; /* Year (calendar year minus 1900) */

    int tm_wday; /* Weekday (0 - 6; Sunday is 0) */

    int tm_yday; /* Day of year (0 -365) */

    int tm_isdst; /* Nonzero if daylight saving time is in effect. */

    };

    These quantities give the time on a 24-hour clock, day of month (1 to 31), month (0 to 11), weekday (Sunday equals 0), year - 1900, day of year (0 to 365), and a flag that is nonzero if daylight saving time is in effect.

    Return Value

    gmtime returns a pointer to the structure containing the time elements. This structure is a static that is overwritten with each call.

    ex:

    #include <time.h>

    #include <iostream.h>

    void main()

    {

    cout<<tm.tm_hour;

    }

    Source(s): by myself
  • Anonymous
    2 decades ago

    #include<time.h>

    void watch()

    {

    long a;

    time(&a);

    printf("\nSystem time now is %s\n\n",ctime(&a));

    }

    這是我的function

    每呼叫一次就會印出時間

    參考一下吧

    2005-01-18 14:25:58 補充:

    這是什麼世界?

  • 2 decades ago

    最基本的C語言有time(),能夠自系統取得某些時間資料。

    如果是C++ ,建議你可以去找尋 STL或是從MSDN找尋MFC,可能會有非常合用的函式。

Still have questions? Get your answers by asking now.