转载自:http://blog.csdn.net/sniper08/archive/2010/04/15/5488640.aspx
COleDateTime、CTime--->CString
这个方法很简单,用Format格式化一个字符串就可以了,详见MSDN
CString--->COleDateTime:
方法1:COleDateTime::ParseDateTime()
CString strDate = _T("1987-06-21");
COleDateTime oleDate;
oleDate.ParseDateTime(strDate, VAR_DATEVALUEONLY);
方法2:COleVariant
CString strDate = _T("1987-06-21");
COleVariant varTime(strDate);
varTime.ChangeType(VT_DATE);
COleDateTime oleDate(varTime);
//COleDateTime oleDate;
//oleDate=varTime;
COleDateTime--->CTime:
方法1:用COleDateTime::GetAsSystemTime(SYSTEMTIME& sysTime)
COleDateTime oleDate(1987, 6, 21, 0, 0, 0);
SYSTEMTIME sysTime;
oleDate.GetAsSystemTime(sysTime);
CTime tm(sysTime);
方法2:用VariantTimeToSystemTime函数
COleDateTime--->SYSTEMTIME--->CTime
COleDateTime oleDate(1987, 6, 21, 0, 0, 0);
SYSTEMTIME sysTime;
VariantTimeToSystemTime(oleDate, &sysTime);
CTime tm(sysTime);
CTime--->COleDateTime:
方法1:用CTime::GetTime()得到time_t
CTime time(1987, 6, 21, 0, 0, 0);
time_t tm = time.GetTime();
COleDateTime oleTime(tm);
方法2:用COleDateTime::GetAsSystemTime(SYSTEMTIME& sysTime)
CTime time(1987, 6, 21, 0, 0, 0);
SYSTEMTIME sysTime;
time.GetAsSystemTime(sysTime);
COleDateTime oleTime(sysTime);
//COleDateTime oleTime;
//oleTime=sysTime;