CTime COleDateTime CString 相互转化

  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;

你可能感兴趣的:(Date)