gpt4 book ai didi

mfc - 想要将 ColeDateTime 转换为 CTime

转载 作者:行者123 更新时间:2023-12-04 00:46:54 26 4
gpt4 key购买 nike

我正在以 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 构造函数接受 SYSTEMTIMEDBTIMESTAMP 结构,因此它们都可以工作:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com