The Windows API, which contains the header file "Windows.h", is required to obtain system time in C/C + +.
The data type of the system time is SYSTEMTIME, and the following definitions can be queried in winbase.h:
typedef struct _systemtime { WORD wyear; WORD Wmonth; WORD Wdayofweek; WORD wday; WORD Whour; WORD Wminute; WORD Wsecond; WORD Wmilliseconds;} SYSTEMTIME, *psystemtime, *lpsystemtime;
It contains 8 messages, such as year, month, day, time, minute, second, millisecond, Day of the week (starting from Monday), all of which are word types.
In vc++6.0, Word is an unsigned short integer and is defined as follows:
typedef unsigned short WORD;
There are two functions to get time: Getlocaltime () gets local time, GetSystemTime () gets Greenwich Mean time.
#include <iostream.h>#include "windows.h" int main () { SYSTEMTIME ct; Getlocaltime (&CT);//local time //getsystemtime (&ct);//gmt time cout<<ct.wyear<< Endl; cout<<ct.wmonth<<Endl; cout<<ct.wday<<Endl; cout<<ct.whour<<Endl; cout<<ct.wminute<<Endl; cout<<ct.wsecond<< Endl; cout<<ct.wmilliseconds<<Endl; Cout<<ct.wdayofweek<<endl;//day of a week, Start from Monday return 0;}
The system time is acquired by C + +