做一个ping命令,显示ping消息是,要在消息前显示系统的时间,怎么办啊?
有没有具体的函数能实现这个功能啊?

解决方案 »

  1.   

    struct tm *today;
    time_t mt; time(&mt);
        today=localtime(&mt); sprintf(&s[0],"%d",today->tm_hour);
    sprintf(&f[0],"%d",today->tm_min);
    sprintf(&m[0],"%d",today->tm_sec);
      

  2.   


    SYSTEMTIME st;
    ::GetSystemTime(&st);
      

  3.   

    char t_now[20];
    struct tm *systime;
    time_t now;
    now = time((time_t *)NULL);
    systime = localtime(&now);
    sprintf(t_now,"%d-%d-%d %d:%d:%d",systime->tm_year+1900,systime->tm_mon+1,systime->tm_mday,
    systime->tm_hour,systime->tm_min,systime->tm_sec);
      

  4.   

    CTime time = CTime::GetCurrentTime();
    CString t = time.Format("%Y-%m-%d %H:%M:%S");
      

  5.   


    使用API函数:GetLocalTimeThe GetLocalTime function retrieves the current local date and time.
      

  6.   

    1: 得到系统时间日期(使用GetLocalTime)
     CString sTime,sYear,sMonth,sDay;
     SYSTEMTIME CurTime;
     GetLocalTime(&CurTime);
     sYear.Format("%d年",CurTime.wYear);
     sMonth.Format("%d月",CurTime.wMonth);
     sDay.Format("%d日",CurTime.wDay);
     sTime =  sYear+ sMonth + sDay;
      // CurTime.wHour
      // CurTime.wMinute
      // CurTime.wSecond IBM的
     AfxMessageBox(sTime);
      

  7.   

    SYSTEMTIME st;
    GetLocalTime(&st);
      

  8.   

        CTime t=CTime::GetCurrentTime( );
        CString s=t.Format("%H:%M:%S"); //时:分:秒
    MessageBox(s);
      

  9.   

    #include"process.h"
    #include"stdio.h"
    main()
    {
    struct   tm   when;   
    time_t  now, result;   
    int    days;   
    time(   &now   );   
    when = *localtime(&now);   
    fprintf("current time is:%s",asctime(&when)); 
    }
    得到的结果就是系统时间。