怎么把一个时间,比如2009-10-10 10:10转化为SYSTEMTIME

解决方案 »

  1.   

    用COleDateTime类处理
    CString s = "2009-10-10 10:10";
    COleDateTime tT;
    tT.ParseDateTime(s);
    SYSTEMTIME st;
    tT.GetAsSystemTime(st);
      

  2.   

    typedef struct _SYSTEMTIME {
       WORD wYear;
       WORD wMonth;
       WORD wDayOfWeek;
       WORD wDay;
       WORD wHour;
       WORD wMinute;
       WORD wSecond;
       WORD wMilliseconds;
    } SYSTEMTIME;
      

  3.   

    bool CTime::GetAsSystemTime(
       SYSTEMTIME& st 
    ) const throw( );
      

  4.   

    然后调用CTime的GetYear,GetDay,GetMonth就可以。
      

  5.   

    你是不是要问:怎么把一个字符串时间,如:"2009-10-10 10:10" 转换为 SYSTEMTIME 结构体吧?
      

  6.   

    1楼的方法就可以了。用ParseDateTime把字符串处理重新复制即可。
      

  7.   

    嗯,1楼正解。COleDateTime类简直就是MFC界处理时间问题的终极法宝!
      

  8.   

    # unsigned __int64 GetTotalMilliseconds(SYSTEMTIME st)  
    # {  
    #     FILETIME ft;  
    #     //把SYSTEMTIME结构的时间转化为 FILETIME结构的时间  
    #     SystemTimeToFileTime(&st,&ft);  
    #     unsigned __int64 temp;  
    #     //利用FILETIME结构计算出时间的毫秒数  
    #     temp = unsigned __int64(ft.dwHighDateTime * 0x100000000L + ft.dwLowDateTime) / 10000L;  
    #      
    #     //返回时间的毫秒数  
    #     return temp ;  
    # }  或者CTime + CTimeSpan
      

  9.   

    CTimeSpan::GetTotalSeconds
    Call this member function to retrieve the total number of complete seconds in this CTimeSpan object.