CString怎么转CTime??

aliyan 2003-11-07 05:47:36
现在我要已经知道了第一个时间的字符串:
t1="031101123023"
也知道了一个时间间隔字符串(分钟),
dt=3
我在算出dt后的时间字符串
t2=??
我想把t1及dt转成CTime进行相加,然后再转成CString,可是CString怎么才可以转成CTime??
...全文
153 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
天限天空 2003-11-07
  • 打赏
  • 举报
回复
up 谢谢 一分
me2love 2003-11-07
  • 打赏
  • 举报
回复
CTime 的类型中,如果我们想得到年、月、日,我们可以使用GetYear(),GetMonth(),GetDay(),
它们的返回值均为int类型,我们可以用CString中的format函数进行转换
ablefirst 2003-11-07
  • 打赏
  • 举报
回复
bluebohe(薄荷) :谢谢前辈在先。
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;



COleDateTime time1(1977,4,16,2,2,2); //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time1, &systime);
CTime tm(systime);
祝你成功!
bluebohe 2003-11-07
  • 打赏
  • 举报
回复
看置顶贴子VC编程经验总结,里面说得比较详细,方法也比楼上通用一些

fingerfox 2003-11-07
  • 打赏
  • 举报
回复
哈哈,各位的工作态度可见一斑阿
ahfeng1980 2003-11-07
  • 打赏
  • 举报
回复
CString buffer;
buffer="20031107182805";
int nYear=atoi(buffer.Left(4));
int nMonth=atoi(buffer.Mid(4,2));
int nDay=atoi(buffer.Mid(6,2));
int nHour=atoi(buffer.Mid(8,2));
int nMin=atoi(buffer.Mid(10,2));
int nSec=atoi(buffer.Right(2));

CTime t1( nYear, nMonth, nDay, nHour, nMin, nSec, -1 );

CTime t2;
CTimeSpan dt;
dt=3*60;
t2=t1+dt;
buffer=t2.Format("%Y-%m-%d %H:%M:%S");
AfxMessageBox(buffer);
aliyan 2003-11-07
  • 打赏
  • 举报
回复
我是要CString转Ctime呀??????
把"031107126305"转成CTime呀??
ahfeng1980 2003-11-07
  • 打赏
  • 举报
回复
不好意思上面写错了:
CString buffer;
buffer=t2.Format("%Y-%m-%d- %H:%M:%S");
AfxMessageBox(buffer);
ahfeng1980 2003-11-07
  • 打赏
  • 举报
回复
CTime t1,t2;
CTimeSpan dt;
dt=3*60;
t2=t1+dt;

CString buffer;
buffer.Format.("%Y-%m-%d- %H:%M:%S");
AfxMessageBox(buffer);
aliyan 2003-11-07
  • 打赏
  • 举报
回复
老兄我是要CString转Ctime!!!!!!!,CTime转Cstring我知道用format??
arvid_gs 2003-11-07
  • 打赏
  • 举报
回复
CTime time1; // Empty CTime. (0 is illegal time value.)
CTime time2 = time1; // Copy constructor.
CTime time3( osBinaryTime ); // CTime from C run-time time
CTime time4( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999
arvid_gs 2003-11-07
  • 打赏
  • 举报
回复
CTime t( 1999, 3, 19, 22, 15, 0 );
// 10:15 PM March 19, 1999
CString s = t.Format( "%A, %B %d, %Y" );

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧