现在我有这样一个字符串
char buf[] = 20:22:219现在我想先把它转换成时间类型
对时间加半小时
再转换成char[]类型的

解决方案 »

  1.   

    int nHour;
    int nMinute;
    int nSecond;
    char buf[] = "20:22:219";
    sscanf( buf, "%0d:%0d:%0d", &nHour, nMinute, nSecond );
    COleDateTime t1(nHour, nMinute, nSecond);
    COleDateTime t2(0, 30, 0);
    t1 += t2;
    sprintf( buf, "%0d:%0d:%0d", t1.GetHour(), t1.GetMinute(), t1.GetSecond() );
      

  2.   

    CTime time;
    sscanf(buf,"%2ld:%2ld:%ld", &time.nHour, &time.nMin, &time.nSec);time.nMin += 30;
    if(time.nMin>=60)
    {
         time.nHour++;
         time.nMin-=60;
    }
    sprintf(buf,"%02ld:%02ld:%ld", time.nHour, time.nMin, time.nSec);
      

  3.   

    大哥我加入
    #include <afxdisp.h>error C2661: 'COleDateTime::COleDateTime' : no overloaded function takes 3 parameters
      

  4.   

    /*COleDateTime(
       int nYear,
       int nMonth,
       int nDay,
       int nHour,
       int nMin,
       int nSec 
    )*/COleDateTime t1(0, 0, 0, nHour, nMinute, nSecond);
    COleDateTime t2(0, 0, 0, 0, 30, 0);
      

  5.   

    to syy64'nHour' : is not a member of 'CTime'
    'nMin' : is not a member of 'CTime'
    ...........
      

  6.   

    to:2000大哥首先,t1 += t2;在我这编译不过,我改成t1 = t1 + t2;
    就可以编译通过了但是,结果显示:-1:-1:-1
      

  7.   

    int nHour;
    int nMinute;
    int nSecond;
    char buf[100] = "20:52:219";
    TRACE("%s\n", buf);
    sscanf( buf, "%ld:%ld:%ld", &nHour, &nMinute, &nSecond );nMinute += 30;
    if ( nMinute >= 60 )
    {
    nMinute -= 60;
    if ( ++nHour >= 24 )
    {
    nHour -= 24;
    }
    }
    sprintf( buf, "%ld:%ld:%ld", nHour, nMinute, nSecond );这个应该行吧
      

  8.   

    谢谢,esprite2000(稀饭)大哥~成功
    另外可以告诉我为什么前面的那个法子不行嘛?最后,请告诉我怎么给分
      

  9.   

    具体问题具体回答
    int nHour;
    int nMinute;
    int nSecond;
    char buf[] = "20:22:21";
    sscanf(buf, "%d:%d:%d", &nHour, &nMinute, &nSecond );
    nMinute += 30;
    sprintf(buf, "%d:%d:%d", nHour, nMinute, nSecond);其他
    int nHour;
    int nMinute;
    int nSecond;
    char buf[] = your_time;
    sscanf(buf, "%d:%d:%d", &nHour, &nMinute, &nSecond );
    nMinute += 30;
    if (nMinute >= 60) 
    {
    nHour+=1;
    nMinute%=60;
    if (nHour >= 24) nHour%=24;
    }
    sprintf(buf, "%d:%d:%d", nHour, nMinute, nSecond);