我想用这种方法取出系统时间,但一直不能如愿!请指教:   SYSTEMTIME st;
   GetSystemTime(&st);
   CString str;
   str.Format("%u:%u:%u",st.wHours,st.wMinutes,st.wSeconds);   运行后分和秒都正确,只有小时不对,总是相差8个小时,不知是为什么?
请高手指教!

解决方案 »

  1.   

    这样取吧:
    CTime currentTime;
    currentTime = CTime::GetCurrentTime();
    CString strTemp;
    strTemp.Format("%u,%u,%u",currentTime.GetHour(),currentTime.GetMinute(),currentTime.GetSecond());
      

  2.   

    你可以用这个 CTime time= CTime::GetCurrentTime();
    CString str;
    str.Format("%d:%d:%d",time.GetHour(),time.GetMinute(),time.GetSecond());
      

  3.   

    The system time is expressed in Coordinated Universal Time (UTC). 
    MSDN上这么说的,取出的时间是格林尼治时间,所以相差8小时,用CTime就不会这样了
      

  4.   

    具体原因我不是很清楚,可以使用GetLocalTime解决此类问题,另外既然你使用MFC使用
    CTime t = CTime::GetCurrentTime()也是不错的解决办法
    在上面代码中你的变量st的属性wHours,wMinutes,wSeconds中是不是多了个s???
      

  5.   

    The GetSystemTime function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC). 上面是MSDN中的说明,好象取出的时间是通用协调时间,我感觉就是所说的格林尼治时间,要+8转化为东8区的北京时间。
      

  6.   

    因为GetSystemTime取的是UTC时间,而我们这里的时间和UTC时间刚好相差8个小时,所以会发生你所说的。改用CTime::GetCurrentTime或者GetLocalTime就可以了!
      

  7.   

    SYSTEMTIME NowTime ;
    GetLocalTime(&NowTime);CString strNewFileName;
    strNewFileName .Format ("%d月%d日%d时%d分%d秒.txt", NowTime.wMonth , NowTime.wDay , NowTime.wHour , NowTime.wHour , NowTime.wMinute , NowTime.wSecond );
      

  8.   

    SYSTEMTIME time;
    GetSystemTime(&time);
    CString str;
    str.Format("%d%d%d%d%d%d",time.wYear,
    time.wMonth,time.wDay,time.wHour,time.wMinute,time.wSecond);
    SetDlgItemText(IDC_EDIT1,str);