The system time is acquired by C + +

Source: Internet
Author: User

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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.