c++以string形式获取系统当前时间
#include<windows.h>
string GetSystemTime()
{
SYSTEMTIME m_time;
GetLocalTime(&m_time);
char szDateTime[100] = { 0 };
sprintf(szDateTime, “%02d-%02d-%02d %02d:%02d:%02d”, m_time.wYear, m_time.wMonth,
m_time.wDay, m_time.wHour, m_time.wMinute, m_time.wSecond);
string time(szDateTime);
return time;
}
使用:
int main()
{
cout<<GetSystemTime()<<endl;
system(“pause”);
}