want to convert ColeDateTime to CTime

余生长醉 提交于 2019-12-08 02:49:53

问题


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.


回答1:


The CTime constructor accepts both SYSTEMTIME and DBTIMESTAMP structures, so both these will work:

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

,

DBTIMESTAMP dbts;
if (dt.GetAsDBTIMESTAMP(dbts))
    t = CTime(dbts);



回答2:


Please try this

COleDateTime dt=COleDateTime(2013, 12, 12,12,12,56);
CTime ctime;
SYSTEMTIME systime;
dt.GetAsSystemTime(systime);
ctime = CTime(systime);


来源:https://stackoverflow.com/questions/7763282/want-to-convert-coledatetime-to-ctime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!