Thanks Jochen And Richard,
Yes I used an OpenSource version of strptime() that I found here: http://plibc.sourceforge.net/doxygen/strptime_8c-source.html[^]- and I have transformef the char(s) into TCHAR, added _T, etc....
and I ave written this:
{
...
CString strFormatCpp = TranslateFormatDate(strFormatVB);
tm timeDate;
memset(&timeDate,0,sizeof(tm ));
TCHAR * pRes = strptime (strMyDate, strFormatCpp, &timeDate);
if ( pRes != NULL )
{
COleDateTime oleDate;
oleDate.SetDateTime(1900 + timeDate.tm_year,timeDate.tm_mon+1,timeDate.tm_mday,timeDate.tm_hour,timeDate.tm_min,timeDate.tm_sec);
}
}
CString TranslateFormatDate(const CString & strFormat)
{
CString strResult;
int nChar = 0;
while ( nChar < strFormat.GetLength() )
{
switch ( strFormat[nChar] )
{
case 'A':
if ( MatchFormatKey(_T("AMPM"),_T("%p"),strFormat, nChar,strResult) )
continue;
break;
case 'a':
if ( MatchFormatKey(_T("ampm"),_T("%p"),strFormat, nChar,strResult) )
continue;
case 'y':
if ( MatchFormatKey(_T("yyyy"),_T("%Y"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("yy"),_T("%y"),strFormat, nChar,strResult) )
continue;
break;
case 'M':
if ( MatchFormatKey(_T("MMMM"),_T("%B"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("MMM"),_T("%b"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("MM"),_T("%m"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("M"),_T("%#m"),strFormat, nChar,strResult) )
continue;
break;
case 'd':
if ( MatchFormatKey(_T("dddd"),_T("%A"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("ddd"),_T("%a"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("dd"),_T("%d"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("d"),_T("%#d"),strFormat, nChar,strResult) )
continue;
break;
case 'h':
if ( MatchFormatKey(_T("hh"),_T("%I"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("h"),_T("%#I"),strFormat, nChar,strResult) )
continue;
break;
case 'H':
if ( MatchFormatKey(_T("HH"),_T("%H"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("H"),_T("%#H"),strFormat, nChar,strResult) )
continue;
break;
case 'm':
if ( MatchFormatKey(_T("mm"),_T("%M"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("m"),_T("%#M"),strFormat, nChar,strResult) )
continue;
break;
case 's':
if ( MatchFormatKey(_T("ss"),_T("%S"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("s"),_T("%#S"),strFormat, nChar,strResult) )
continue;
break;
}
strResult+=strFormat[nChar];
nChar++;
}
return strResult;
}
bool MatchFormatKey(const CString & strKey,const CString & strTransKey,const CString & strFormat, int & nPos,CString & strResult)
{
if ( strFormat.Mid(nPos, strKey.GetLength()) != strKey )
return false;
strResult+=strTransKey;
nPos+=strKey.GetLength();
return true;
}
Thanks every-one!
Jerry
modified 18-Jul-12 9:49am.
|