比如1977年12月12日12点15分30秒
怎么转为秒表示?

解决方案 »

  1.   

    将日期分解,写入 struct tm内,然后调用 mktime 得到秒为单位的时间struct  tm;
    memset(&tm, 0, sizeof(tm));
    tm.tm_year = 77;
    tm.tm_mon = 12;
    tm.tm_mday = 12;
    tm.tm_hour = 12;
    tm.tm_min = 15;
    tm.tm_sec = 30;time_t  t = mktime(&tm);
      

  2.   

    CTime t( 1997, 12, 12, 12, 15, 30 ); 
    time_t osBinaryTime = t.GetTime(); // time_t defined in <time.h>
    printf( "time_t = %ld\n", osBinaryTime );
    osBinaryTime就是从1970年1月1日0:0:0秒到1977年12月12日12点15分30秒的秒数
      

  3.   

    另外,我核了一下,CTime的计算是基于标准的国际时间的,如果要算北京时间,基数应该是
    1970年1月1日8:0:0
      

  4.   

    CTime::GetTimeSee Also
    CTime Overview | Class Members | Hierarchy Chart | CTime::CTime
    Returns a __time64_t value for the given CTime object.__time64_t GetTime( ) const throw( );
    Return Value
    GetTime will return the number of seconds between the current CTime object and January 1, 1970.Example
    // Example for CTime::GetTime
    CTime t( 1999, 10, 20, 23, 50, 0 ); // 11:50 PM October 20, 1999
    time_t osBinaryTime = t.GetTime();  // time_t defined in <time.h>
    printf( "time_t = %ld\n", osBinaryTime );
      

  5.   

    感谢 keiy() 做出这么详细的回答,结贴