定义了一个CTime对象,并通过CTime::GetCurrentTime()获得当前时间,但是怎么能转换成字符串呢?
我以前用的分别GetYear、Month等的方法自己都觉得笨,^_^

解决方案 »

  1.   

    CTime t = CTime::GetCurrentTime();
    CString str;
    str = t.Format("%Y-%M-%d");
      

  2.   

    CString sTime = CTimeX.Format("%Y-%m-%d");
      

  3.   

    // example for CTime::Format and CTime::FormatGmt
    CTime t( 1999, 3, 19, 22, 15, 0 ); 
    // 10:15PM March 19, 1999
    CString s = t.Format( "%A, %B %d, %Y" );
    ASSERT( s == "Friday, March 19, 1999" );
      

  4.   

    CTime t = CTime::GetCurrentTime();
    CString str;
    str = t.Format("%Y-%m-%d %H-%M-%S");
      

  5.   

    CTime t = CTime::GetCurrentTime();
    CString str;
    str = t.Format("%Y-%m-%d %H-%M-%S");同意楼上
      

  6.   

    CTime t=CTime::GetCurrentTime();
    如:int year,mon,day;
    year=t.getYear();
    mon=t.getMon();
    day=t.getDay();
    CString str;
    str.format("%d%d%d",year,mon,day);
    任你转换
      

  7.   

    CTime t=CTime::GetCurrentTime();
    CString strtime = t.Format("%Y-%m-%d %H:%M:%S");
      

  8.   

    呵呵,我知道了。昨天刚刚找到的。谢谢楼上各位。
    sxy521的方法跟我自己原来的方法差不多,^_^,感觉有点笨