将合法的日期-时间字符串,如:2005-05-03  12:24:20  转化为一个结构中,如tm结构.  
API函数,自己写的函数,或现成的类都可以.  
MFC类除外呀!  
 
先谢谢了.

解决方案 »

  1.   

    用COleDateTime::ParseDateTime()函数转换.
      

  2.   

    用sscanf函数。
    tm times = {0};
    char  tokenstring[] = "2005-05-03  12:24:20";
    sscanf( tokenstring, “%d-%d-%d  %d:%d:%d”, &times.tm_year ,  &times.tm_mon,
    &times.tm_mday,&times.tm_hour,&times.tm_min,&times.tm_sec );
      

  3.   

    bool CptTime::Format(STimeInfo& si,const char* pcDateTime) const
    {
    assert(pcDateTime!=NULL) ; if(!this->IsValidFormat(pcDateTime))
    {
    return false ;
    } char szCopy[20+1] = {0} ; ::strcpy(szCopy,pcDateTime) ; char* pcTem = ::strtok(szCopy,"-") ;
    si.wYear = ::atoi(pcTem) ; pcTem = ::strtok(NULL,"-") ;
    si.wMonth = ::atoi(pcTem) ; pcTem = ::strtok(NULL," ") ;
    si.wDay = ::atoi(pcTem) ; pcTem = ::strtok(NULL,":") ;
    si.wHour = ::atoi(pcTem) ; pcTem = ::strtok(NULL,":") ;
    si.wMinute = ::atoi(pcTem) ; pcTem = ::strtok(NULL,":") ;
    si.wSecond = ::atoi(pcTem) ; return true ;
    }
      

  4.   

    谢谢三位了. 
    其实我希望能支持多种格式的时间类型:如
    "25 January 1996"
    "8:30:00"
    "20:30:00"
    "January 25, 1996 8:30:00"
    "8:30:00 Jan. 25, 1996"
    "1/25/1996 8:30:00"To: lzzqqq(Jonersen),我不能用MFC类,能有其他类吗(你收集和写的都行)?
    To: wangk(倒之),有支持上述格式的吗?
    To: Practise_Think(时代“过客”),CptTime是什么类呀?请问你有完整代码吗?
      

  5.   

    To:Practise_Think(时代“过客”) ,
    难道就没现成的类,API函数,运行库函数支持将所有正确格式的时间字符串转化为时间结构吗?