C/C++ 调用API获取当前时间
#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;
}
    文章出处:https://www.cnblogs.com/LyShark/p/9158588.html
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号