3

I am reading a datetime from database in a ColeDateTime format. I want to convert it to CTime to get the date month year and time.

CString repDt; //**this will hold the datetime which i read from Database**

COleDateTime dt; 
//**my datetime format is mm/dd/yyyy.**

dt.ParseDateTime(repDt);   **//this line of code gives exception**

CTime t(dt.GetYear(), dt.GetMonth(), dt.GetDay(), dt.GetHour(),
        dt.GetMinute(), dt.GetSecond());
m_time=t.GetTime();

Please give me some solution how could I do this?

Thanks in advance.

4

2 回答 2

4

构造CTime函数同时接受SYSTEMTIMEDBTIMESTAMP结构,因此它们都可以工作:

SYSTEMTIME st;
if (dt.GetAsSystemTime(st))
    t = CTime(st);

,

DBTIMESTAMP dbts;
if (dt.GetAsDBTIMESTAMP(dbts))
    t = CTime(dbts);
于 2011-10-20T15:43:39.073 回答
1

请试试这个

COleDateTime dt=COleDateTime(2013, 12, 12,12,12,56);
CTime ctime;
SYSTEMTIME systime;
dt.GetAsSystemTime(systime);
ctime = CTime(systime);
于 2013-05-24T14:27:00.580 回答