我需要把日期型的值转换为字符型的数值,用哪个函数实现?

解决方案 »

  1.   

    我都不知道帖了多少次了:CString str;
    CTime t = CTime::GetCurrentTime();
    str.Format("%d-%d-%d",t.GetYear(),t.GetMonth(),t.GetDay());CString strTime;
    CTime tTime = CTime::GetCurrentTime();
    strTime = tTime.Format("%Y-%m-%d %H:%M:%S");
      

  2.   

    CTime::Format 
    CString Format( LPCTSTR pFormat ) const;CString Format( UINT nFormatID ) const;Return ValueA CString that contains the formatted time.ParameterspFormatA formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are replaced by the corresponding CTime component. Other characters in the formatting string are copied unchanged to the returned string. See the run-time functionstrftime for details. The value and meaning of the formatting codes for Format are listed below: %D   Total days in this CTime
    %H   Hours in the current day
    %M   Minutes in the current hour
    %S   Seconds in the current minute
    %%   Percent sign 
    nFormatIDThe ID of the string that identifies this format. ResCall this member function to create a formatted representation of the date/time value. If the status of this CTime object is null, the return value is an empty string. If the status of CTime is invalid, the return value is an empty string.Example// 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" );CTime Overview |  Class Members |  Hierarchy ChartSee Also   CTime::FormatGmt
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.
      

  3.   

    CTime time;
    time=CTime::GetCurrentTime();
    CString stringTime=time.Format("%H:%M:%S");
    如果是日期的话,应是同理吧!