C++的开发时间字符串,星期为中文,精确到毫秒
只两天在做C++的开发,需要一个时间的字符串,星期为中文,精确到毫秒。网上查了一些资料总结如下:
#include <windows.h>
string getTimeNow()
{
SYSTEMTIME sys;
GetLocalTime(&sys);
char nowTime[40];
char *Week[7] = { "星期天","星期一","星期二","星期三","星期四","星期五","星期六" };
sprintf_s(nowTime, "%4d/%02d/%02d %03s %02d:%02d:%02d.%03d"
, sys.wYear, sys.wMonth, sys.wDay
, Week[sys.wDayOfWeek]
, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
return nowTime;
}