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

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

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