想要将ColeDateTime转换为CTime [英] want to convert ColeDateTime to CTime

查看:363
本文介绍了想要将ColeDateTime转换为CTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以ColeDateTime格式从数据库读取日期时间.我想将其转换为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?

谢谢.

推荐答案

CTime构造函数同时接受SYSTEMTIMEDBTIMESTAMP结构,因此它们都将起作用:

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

这篇关于想要将ColeDateTime转换为CTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆