zoukankan      html  css  js  c++  java
  • C/C++获取系统时间

    C/C++获取系统时间需要使用Windows API,包含头文件"windows.h"。

    系统时间的数据类型为SYSTEMTIME,可以在winbase.h中查询到如下定义:

    typedef struct _SYSTEMTIME {
        WORD wYear;
        WORD wMonth;
        WORD wDayOfWeek;
        WORD wDay;
        WORD wHour;
        WORD wMinute;
        WORD wSecond;
        WORD wMilliseconds;
    } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;

    其中包含了年、月、日、时、分、秒、毫秒、一周中的第几天(从周一开始计算)等8条信息,均为WORD类型。

    在VC++6.0中WORD为无符号短整型,定义如下:

    typedef unsigned short      WORD;

    获取时间的函数有两个:GetLocalTime()获取本地时间;GEtSystemTime()获取格林尼治标准时间。

    #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;
    }
  • 相关阅读:
    还原被删除的对象(域)
    Windows blue系列的安装
    转移active directry数据库文件
    使用指针让两个数交换
    针对被删除的AD DS对象执行授权还原
    这两天的总结
    小小问题
    程序2
    程序4
    程序1
  • 原文地址:https://www.cnblogs.com/tangxin-blog/p/4078378.html
Copyright © 2011-2022 走看看