首页 > 编程语言 > 详细

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

时间:2018-06-09 11:17:20      阅读:336      评论:0      收藏:0      [点我收藏+]
#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获取当前时间

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!