开发者

want to convert ColeDateTime to CTime

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.


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);


Please try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜