题目:
  编写一个函数,用时间作为函数的三个参数(时,分,秒),返回自最近12点钟到现在的秒数。用这个函数计算两次时间之的秒数(假定再次时间都在同一个12小时的时间周期内)。

解决方案 »

  1.   

    获得时分秒
    CTime m_Time=CTime::GetCurrentTime();
    m_Time.GetHour();
    m_Time.GetMinute();
    m_Time.GetSecond();
      

  2.   

    VOID GetSystemTime(
      LPSYSTEMTIME lpSystemTime   // address of system time structure
    );
    其中,SYSTEMTIME定义如下:
    typedef struct _SYSTEMTIME {  // st 
        WORD wYear; 
        WORD wMonth; 
        WORD wDayOfWeek; 
        WORD wDay; 
        WORD wHour; 
        WORD wMinute; 
        WORD wSecond; 
        WORD wMilliseconds; 
    } SYSTEMTIME;
      

  3.   

    SYSTEMTIME sysTime;
    GetSystemTime(&sysTime); //GMT time
    or 
    GetLocalTime(&sysTime); //your time such as BEIJING timethen you can :
    sysTime.wYear get year, 
    sysTime.wMonth get month,
    ...for detail see struct:
    typedef struct _SYSTEMTIME {  // st 
        WORD wYear; 
        WORD wMonth; 
        WORD wDayOfWeek; 
        WORD wDay; 
        WORD wHour; 
        WORD wMinute; 
        WORD wSecond; 
        WORD wMilliseconds; 
    } SYSTEMTIME;
      

  4.   

    对于 greenever(司马青杉)所说,我觉得没有必要用后三个函数
    直接用Format函数就可以了