码迷,mamicode.com
首页 > 编程语言 > 详细

C++调用API获取当前时间

时间:2018-06-09 11:26:35      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:har   api   local   namespace   mes   sys   ace   string   pac   

#include <string> 
#include<iostream>
#include<windows.h>
#include <sstream>
using namespace std;

string WORDToString(WORD w)
{
    char tmpbuff[16];
    sprintf(tmpbuff,"%d",w);
    string res=tmpbuff;
    return res;
}
string getTime()
{
    string week[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
    SYSTEMTIME now;   
    string currentTime;  
    GetLocalTime( &now );   
    currentTime=WORDToString(now.wYear)+""  
        +WORDToString(now.wMonth)+""  
        +WORDToString(now.wDay)+"" 
        +"("+week[now.wDayOfWeek]+") "
        +WORDToString(now.wHour)+":"  
        +WORDToString(now.wMinute)+":"  
        +WORDToString(now.wSecond)+" "  
        +WORDToString(now.wMilliseconds)+"ms";  
    return currentTime;
}
int main() 
{ 
    cout<<getTime()<<endl;
    return 0;
}

 

C++调用API获取当前时间

标签:har   api   local   namespace   mes   sys   ace   string   pac   

原文地址:https://www.cnblogs.com/LyShark/p/9158588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!