SYSTEMTIME ti;
CString str;
GetSystemTime(&ti);
str.Format("%02d:%02d:%02d:%03d",(ti.wHour),ti.wMinute,ti.wSecond,ti.wMilliseconds);
MessageBox(str,"",0);
用这个获取时间,为什么16点获得的 ti.wHour 是8。

解决方案 »

  1.   

    Retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC), 还需要转换吧.
      

  2.   

    GetSystemTime获取的是系统时间,也叫格林威治时间或者全球标准时间,简称叫做UTC。本地时间就是相对于UTC而言的,比如中国北京是在东8区,相对于UTC就多了8个小时。一般使用到的时间都是使用本地时间,也就是调用函数GetLocalTime。
      

  3.   


            SYSTEMTIME systime;
    memset(&systime, 0, sizeof(SYSTEMTIME));
    GetLocalTime(&systime);
    CString str;
    char * buf = new char[20];
    if ( NULL == buf)
    {
        str = "";
    } memset(buf, 0, 20);
    _stprintf(buf, 
    TEXT("%04d-%02d-%02d %02d:%02d:%02d"), 
    systime.wYear, systime.wMonth, systime.wDay, 
    systime.wHour, systime.wMinute, systime.wSecond); str = buf; 
    delete [] buf;
      

  4.   

    用 GetLocalTime 才是当地时间, GetSystemTime 是跟时区有关的