怎样处理这样的时间问题:
1970-1-1 00:00:00 加上1237473400秒数后的时间?
用time怎样实现呢?

解决方案 »

  1.   

    把1970-1-1 00:00:00转化为秒
    加上1237473400
    struct tm *newtime;
    newtime = localtime( &aclock );  
    printf( "The current date and time are: %s", asctime( newtime ) );
    就能得到新时间
    #include <time.h>
    #include <stdio.h>这样的函数很多,可以查下MSDN看看
      

  2.   

    一天有多少秒是确定的,先转化为XX天XX小时XX分XX秒,下来...好像不太难吧!
      

  3.   

    1.把1971年到2038年的时间秒钟存到sec_year[]中
       for(i=1971;i<=2038;i++)
       {
          if((i%400==0)||(i%100!=0&&i%4==0))
             
                 sec_year[i-1971]=366*24*60*60;          
          else 
             sec_year[i-1971]=sec_year[i-1971-1]+365*24*60*60;
       }
    2.找出是哪一年
       LONGLONG t,t1,t2,t3;//时间秒
       for(i=1971;i<=2038;i++)
       {
         if(t<sec_year[0])
           YEAR=1970;
         if(t>=sec_year[i-1971]&&t<sec_sec_year[i-1971+1])
            YEAR=i;
        }
    3.把月的秒钟数存入sec_month[]中
        sec_month[0]=31*24*60*60;
        if(YEAR%400==0||YEAR%100!=0&&YEAR%4==0)
        sec_month[1]=sec_montn[0]+29*24*60*60;
        else
        sec_month[1]=sec_month[0]+28*24*60*60;   .......
       把12个月的时间都存入sec_month[]
    4.寻找是哪个月MONTH
       方法同寻找哪一年相仿,
       记住是剩下的秒钟数
       t1=t-sec_year[YEAR-1971]5.找出是那一天DAY
      t2=t1-sec_month[MONTH-1];
      int DAY=t2/(24*60*60)+1;
    6.找出时间
      t3=t2%(24*60*60)
      SEC=t3%60;
      t3=t3/60;
      MIN=t3%60;
      HOUR=t3/24;
    7.显示时间(YEAR-MONTH-DAY HOUR:MIN:SEC)
      
      
      

  4.   

    //已经连接上服务器 处理接收到的数据
    recv(m_hSocket, (char *) &m_ulTime, 4, 0);
    /*  获得其余的32个位元值,这时最后的参数是0,用于从伫列中删除其他讯息。
    接收的32位元的m_ulTime值是从1990年1月1日开始的0:00 UTC秒数
    但最高顺序的位元组是第一个位元组,因此该值必须通过ntohl(「network-to-host long」)
    函数处理来调整位元组顺序,
    以便Intel微处理器能够处理。然后调用ChangeSystemTime函数。 */
    m_ulTime = ntohl(m_ulTime);   
    FILETIME    ftNew;     
        SYSTEMTIME  stOld,stNew;
    GetLocalTime(&stOld);   
        stNew.wYear         = 1900;
        stNew.wMonth        = 1 ;
        stNew.wDay          = 1 ;
        stNew.wHour         = 0 ;
        stNew.wMinute       = 0 ;
        stNew.wSecond       = 0 ;
        stNew.wMilliseconds = 0 ;
    SystemTimeToFileTime (&stNew, &ftNew);
        /*  将SYSTEMTIME结构设定为1900年1月1日午夜(0时)。
     并将这个SYSTEMTIME结构传递给SystemTimeToFileTime,将此结构转化为FILETIME结构。
     FILETIME实际上只是由两个32位元的DWORD一起组成64位元的整数,
     用来表示从1601年1月1日至今间隔为100奈秒(nanosecond)的间隔数。
    */      LARGE_INTEGER li ; //64位大整数
        li = * (LARGE_INTEGER *) &ftNew;
        li.QuadPart += (LONGLONG) 10000000 * m_ulTime; 
        ftNew = * (FILETIME *) &li;
        FileTimeToSystemTime (&ftNew, &stNew);     if (::SetSystemTime (&stNew)) //调用SetSystemTime来设定时间
         {
     ::GetLocalTime (&stNew);
              this->FormatUpdatedTime (&stOld, &stNew); 
         }
    可以看看这个 从时间服务器上获得的是从1900年1月1日的时间
    你可以把1970年那段时间计算成秒数 加上后面的秒数 就转化成了上面的格式了
    这样直接调用那个时间函数就可以了