Conversion between C ++ datetime and string
VC6
Cstring stime = _ T ("13:20:30 ");
Char * chartime = (lpstr) (lpctstr) stime;
Cstring sformat = _ T ("% d-% d: % d ");
Char * charformat = (lpstr) (lpctstr) sformat;
Int nyear;
Int nmonth;
Int ndate;
Int nhour;
Int Nmin;
Int nsec;
Stscanf (chartime, charformat, & nyear, & nmonth, & ndate, & nhour, & Nmin, & nsec );
Ctime T (nyear, nmonth, ndate, nhour, Nmin, nsec );
Cstring S = T. Format (_ T ("% Y % m month % d % H % m minute % s second "));
VC2005
Chinese format not included
Stscanf (chartime, charformat, & nyear, & nmonth, & ndate, & nhour, & Nmin, & nsec );
Cstring stime = _ T ("12:40:10 ");
Tchar * chartime = (tchar *) (lpctstr) stime;
CString sFormat = _ T ("% d-% d: % d ");
TCHAR * charFormat = (TCHAR *) (LPCTSTR) sFormat;
Int nYear;
Int nMonth;
Int nDate;
Int nHour;
Int nMin;
Int nSec;
_ Stscanf (charTime, charFormat, & nYear, & nMonth, & nDate, & nHour, & nMin, & nSec );
CTime t (nYear, nMonth, nDate, nHour, nMin, nSec );
CString s = t. Format (_ T ("% Y-% m-% d % H: % M: % S "));
Chinese format
To include # include <locale. h>
CString sTime = _ T ("12:40:10 ");
TCHAR * charTime = (TCHAR *) (LPCTSTR) sTime;
CString sFormat = _ T ("% d-% d: % d ");
TCHAR * charFormat = (TCHAR *) (LPCTSTR) sFormat;
Int nYear;
Int nMonth;
Int nDate;
Int nHour;
Int nMin;
Int nSec;
_ Stscanf (charTime, charFormat, & nYear, & nMonth, & nDate, & nHour, & nMin, & nSec );
CTime t (nYear, nMonth, nDate, nHour, nMin, nSec );
_ Tsetlocale (LC_ALL, _ T ("Chinese-simplified"); // localized
CString s = t. Format (_ T ("% Y % m month % d % H % M minute % S second "));