请问VC如何获取系统时间,非MFC工程,不支持CString...

解决方案 »

  1.   

    time();
    现在用vc的都对c库没概念了嘛?
    http://msdn.microsoft.com/en-us/library/w4ddyt9h(VS.80).aspx
      

  2.   

    SYSTEMTIME time;
    GetLocalTime(&time);
      

  3.   

    SYSTEMTIME time;
    GetLocalTime(&time);
    通用
      

  4.   

    SYSTEMTIME time;
    GetLocalTime(&time);
      

  5.   

    SYSTEMTIME st;
    GetLocalTime(&st);再把st中的内容转成您想要的格式。
      

  6.   

    API函数:
    SYSTEMTIME Time;
    GetLocalTime(&Time);
    C/C++:
    timeb tmb;
    ftime(&tmb);
    tm *p_tm = localtime((const time_t *)&tmb.time);
    char sz_time[1024] ={0};

    sprintf(sz_time, 
    "%04d-%02d-%02d %02d:%02d:%02d.%03d", 
    p_tm->tm_year+1900,
    p_tm->tm_mon+1,
    p_tm->tm_mday,
    p_tm->tm_hour,
    p_tm->tm_min,
    p_tm->tm_sec,
    tmb.millitm);
      

  7.   

    加上头文件
    #include <sys/timeb.h>
      

  8.   

    可以用C语言函数time(),也可以用API函数GetLocalTime
      

  9.   

    SYSTEMTIME time;
    GetLocalTime(&time);这个UP~
      

  10.   

    不晓得LZ为什么特别强调不能用CString
    void GetSystemTime(
      LPSYSTEMTIME lpSystemTime
    );
    void GetLocalTime(
      LPSYSTEMTIME lpSystemTime
    );
      

  11.   

    可能lz建的不是MFC工程,Maybe Win32 Application
      

  12.   

    接点分. 
    #include <time.h>
    #include <string>
    #include <iostream>
    std::string FormateDateTime(time_t t = time(NULL))
    {
    char szData[256] = {0};
    tm* ptm = localtime(&t);
    sprintf(szData, "%d-%.2d-%.2d %.2d:%.2d:%.2d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
    return szData;
    }int main()
    {
        std::string strTime = FormateDateTime();    std::cout << strTime;
        return 0;
    }
      

  13.   


    Win32 App不也可以用MFC,哈哈我是没明白CString和时间有啥关系
      

  14.   

    CString和时间的关系应该就是那个Format吧.
      

  15.   

    static CString strTemp;
    SYSTEMTIME st;
            GetLocalTime(&st);
    // 刷新时间
    strTemp.Format("现在时间 %02i:%02i:%02i ",st.wHour,st.wMinute,st.wSecond);
    GetDlgItem(IDC_CURTIME)->SetWindowText(strTemp);
      

  16.   

    虽然不是MFC工程,但GetLocalTime()和GetSystemTime()两个函数都可以用呀。我也是这么用的