CString 版
CString GetTimestamp()
{
CString nowTime;
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
time_t unixTime;
time(&unixTime);
CString cs_uninxtime;
CString cs_milliseconds;
cs_uninxtime.Format(L"%ld", unixTime);
cs_milliseconds.Format(L"%ld", sysTime.wMilliseconds);
nowTime = cs_uninxtime + cs_milliseconds;
//nowTime.Format(_T("%ld%ld"), unixTime, sysTime.wMilliseconds);//输出UNIX时间戳字符串
return nowTime;
}
wstring 版
std::wstring GetTimestamp()
{
wstring nowTime;
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
time_t unixTime;
time(&unixTime);
wstring ws_uninxtime;
wstring ws_milliseconds;
ws_uninxtime = to_wstring(unixTime);
//
wstringstream ss;
ss << setw(3) << setfill(L'0') << sysTime.wMilliseconds;
ws_milliseconds = ss.str();
//
nowTime = ws_uninxtime + ws_milliseconds;
return nowTime;
}