获取当前的日期

win api 获取当前的日期

void GetCurTime(char* szTime)
{
	SYSTEMTIME sysTime;
	
	assert(szTime);

	//获取当前时间
	::GetLocalTime(&sysTime);
	sprintf(szTime, "%d-%d-%d %d:%d:%d:%d ", sysTime.wYear, sysTime.wMonth, sysTime.wDay,
		sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds);
}
 


ansi c 获取当前时间

BOOL GetCurrTime(char* lpszTime, int lpszDate)
{
	time_t	rt		= {0};
	tm*		ptmInfo	= NULL;

	
	try
	{
		time(&rt);
		ptmInfo = localtime(&rt);

		if (lpszTime)
		{
			sprintf(lpszTime, "%d-%d-%d %d:%d:%d", ptmInfo->tm_year + 1900, ptmInfo->tm_mon, ptmInfo->tm_mday,
				ptmInfo->tm_hour, ptmInfo->tm_min, ptmInfo->tm_sec);
		}

		if (lpszDate)
		{
			sprintf(lpszTime, "%d-%d-%d", ptmInfo->tm_year + 1900, ptmInfo->tm_mon, ptmInfo->tm_mday);
		}
	}
	catch (...)
	{
		return FALSE;
	}

	return TRUE;
}
 

 

你可能感兴趣的:(C++,c,C#)