我正在以 ColeDateTime
格式从数据库中读取日期时间。我想将它转换为 CTime
以获得日期月份年份和时间。
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();
请给我一些解决方案,我该怎么做?
提前致谢。
最佳答案
CTime
构造函数接受 SYSTEMTIME
和 DBTIMESTAMP
结构,因此它们都可以工作:
SYSTEMTIME st;
if (dt.GetAsSystemTime(st))
t = CTime(st);
,
DBTIMESTAMP dbts;
if (dt.GetAsDBTIMESTAMP(dbts))
t = CTime(dbts);
关于mfc - 想要将 ColeDateTime 转换为 CTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7763282/