[求助]如何获取本机时间,并用自00:00:00 UTC, January 1, 1970的秒数来表示?

解决方案 »

  1.   

    CTime::GetCurrentTime();
    CTime::GetGmtTm ();
    CString str;
    str.Format("%d:%d...",time.GetYear()...);
      

  2.   

    CTime tm;tm=CTime::GetCurrentTime();CString str;
    str=tm.FormatGmt("%S:%M:%H UTC , %b %d , %Y");
      

  3.   

    SORRY,我没说清楚 ,是要求“自00:00:00 UTC, January 1, 1970的秒数”来表示,如245734626523秒。
      

  4.   

    void main( void )
    {
       time_t ltime = 245734626523;   time( &ltime );
       printf( "The time is %s\n", ctime( &ltime ) );
    }ctime函数,见MSDN
      

  5.   

    你这个数也太大了,都超出了UINT能表示的范围,你从哪里算出这个数的?
      

  6.   

    time_t nSecond;::time(&nSecond);
    int n=(int)nSecond;
      

  7.   

    就是.只有一个dword的表示范围..
      

  8.   

    CTime curtime;
    curtime=CTime::GetCurrentTime();
    int year=curtime.GetYear();
    int month=curtime.GetMonth();
    int day=curtime.GetDay();
    int hour=curtime.GetHour();
    int minute=curtime.GetMinute();
    int second=curtime.GetSecond();
      

  9.   

    不是呀,不是呀,我是说先获取本机时间,然后用“自00:00:00 UTC, January 1, 1970的秒数”来表示出来。
      

  10.   

    我曾经做过一个工程,要求把1970开始到某一个时刻的秒数转换为现在的时间格式,你这个正好相反,在msdn里有个类或者函数,可以直接转化,不需要涉及算法。我的资料忘了放在那里,你可以去看看《vc宝殿》里面肯定友,若你还是不能,可以来信询问[email protected]
      

  11.   

    time_t nSecond;::time(&nSecond);nSecond就是自00:00:00 UTC, January 1, 1970的秒数表示的本机时间
      

  12.   

    见MSDN:
        /* Get UNIX-style time and display as number and string. */
        time( &ltime );
        printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
        printf( "UNIX time and date:\t\t\t%s", ctime( &ltime ) );
      

  13.   

    dingkl()说的好像对,请使用!
      

  14.   

    FILE* myself;
    myself = fopen("a.txt", "a++"); 
    fwrite(&nSecond,sizeof(int),1, myself);
    fclose(myself);
    return;time_t 不是LONG类型的吗?为什么写进文件是乱码?
      

  15.   

    应该是:fprintf(myself,"%d",nSecond);而不是fwrite(&nSecond,sizeof(int),1,mySelf);