您的位置:首页 > 编程语言 > C语言/C++

C++ 获取当前日期时间 毫秒级

2012-04-10 14:29 281 查看
返回的日期时间的格式 如:2012/04/10 14:32:25.456



CString GetTimeStr() 
{ 
	SYSTEMTIME time;
	GetLocalTime(&time);

	CString year;
	CString month;
	CString day;
	year.Format(_T("%d"), time.wYear);
	month.Format(_T("%d"), time.wMonth);
	day.Format(_T("%d"), time.wDay);
	month = time.wMonth < 10 ? (_T("0") + month):month;
	day = time.wDay < 10 ? (_T("0") + day):day;
	wstring strTime = year + _T("/") + month + _T("/") + day + _T(" ");

	WCHAR* pTime = new WCHAR[30];
	wstring strFormat = _T("HH:mm:ss");
	GetTimeFormat(LOCALE_INVARIANT , LOCALE_USE_CP_ACP, &time, strFormat.c_str(), pTime, 30);
	strTime += pTime;

	CString milliseconds;
	milliseconds.Format(_T("%d"), time.wMilliseconds);
	strTime += _T(".") + milliseconds;
	return strTime.c_str();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: