我建了一个 控键变量 m_t 想让他显示系统时间怎么 取  (是否要转换日期型为字符串)

解决方案 »

  1.   

    CTime time = CTime::GetCurrentTime();
    CString stime = time.Format("%a, %d %b %Y %H:%M:%S %z");
      

  2.   

    // 得到日期如20030322 14:12:34
    CString CNDSTimer::getTimeInYear()
    {
    char szYear[5];
    char szMonth[3];
    char szDay[3];
    char szHour[3];
    char szMinute[3];
    char szSecond[3];
    char szValue[30]; SYSTEMTIME time;
    ::GetLocalTime(&time);
    itoa(time.wYear,szYear,10);
    ::strcpy(szValue,szYear); itoa(time.wMonth,szMonth,10);
    if (time.wMonth<10)
    ::strcat(szValue,"0");
    strcat(szValue,szMonth);

    itoa(time.wDay,szDay,10);
    if (time.wDay <10)
    ::strcat(szValue,"0");
    strcat(szValue,szDay); itoa(time.wHour,szHour,10);
    if (time.wHour <10)
    ::strcat(szValue,"0");
    strcat(szValue,"  ");
    strcat(szValue,szHour); itoa(time.wMinute,szMinute,10);
    strcat(szValue,":");
    if (time.wMinute <10)
    ::strcat(szValue,"0");

    strcat(szValue,szMinute); itoa(time.wSecond,szSecond,10);
    strcat(szValue,":");
    if (time.wSecond <10)
    ::strcat(szValue,"0");

    strcat(szValue,szSecond); return CString(szValue);
    }
      

  3.   

    COleDateTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
      

  4.   

    同意skyzxg(sky) 的方法,最简单、直接。