我正在从数据库中读取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();请给我一些解决方案,我该怎么做呢?
提前谢谢。
发布于 2011-10-20 23:43:39
CTime构造函数同时接受SYSTEMTIME和DBTIMESTAMP结构,因此这两种结构都可以工作:
SYSTEMTIME st;
if (dt.GetAsSystemTime(st))
t = CTime(st);,
DBTIMESTAMP dbts;
if (dt.GetAsDBTIMESTAMP(dbts))
t = CTime(dbts);发布于 2013-05-24 22:27:01
请试试这个
COleDateTime dt=COleDateTime(2013, 12, 12,12,12,56);
CTime ctime;
SYSTEMTIME systime;
dt.GetAsSystemTime(systime);
ctime = CTime(systime);https://stackoverflow.com/questions/7763282
复制相似问题