CnCrypt代码 之 SYSTEMTIME转字符串,字符串转SYSTEMTIME

LPWSTR	SystemTimeToString(SYSTEMTIME& st, LPWSTR lpFileTime)
{
	swprintf(lpFileTime, L"%d-%02d-%02d %02d:%02d:%02d",
		(int)st.wYear,
		(int)st.wMonth,
		(int)st.wDay,
		(int)st.wHour,
		(int)st.wMinute,
		(int)st.wSecond
		);
	return lpFileTime;
}


BOOL	StringToSystemTime(LPCWSTR lpString, SYSTEMTIME &time)
{
	if (lpString == NULL)
	{
		return FALSE;
	}

	int         nYear = 0;
	int         nMonth = 0;
	int         nDay = 0;
	int         nHour = 0;
	int         nSecond = 0;
	int         nMinute = 0;
	swscanf(lpString, L"%d-%d-%d %d:%d:%d", &nYear, &nMonth, &nDay, &nHour, &nMinute, &nSecond);

	if (nMonth == 0 || nDay == 0)
	{
		swscanf(lpString, L"%d/%d/%d %d:%d:%d", &nYear, &nMonth, &nDay, &nHour, &nMinute, &nSecond);
	}

	time.wYear = (WORD)nYear;
	time.wMonth = (WORD)nMonth;
	time.wDay = (WORD)nDay;
	time.wHour = (WORD)nHour;
	time.wSecond = (WORD)nSecond;
	time.wMinute = (WORD)nMinute;
	time.wMilliseconds = 0;

	return TRUE;
}

你可能感兴趣的:(CnCrypt代码 之 SYSTEMTIME转字符串,字符串转SYSTEMTIME)