求一函数,如何把系统时间读出来精确到微秒 
DecodeTime(Present,hour,Min,Sec,MSec); 
上面这个函数是精确到豪秒的,有精确的微秒的么? 
拜求

解决方案 »

  1.   

    没有, windows 内核是以 毫秒 为单位, 所以最大精确也就只能到毫秒极
      

  2.   

    你封装一个函数var
      Year,month,day,H,M,S,MS: word;
      t:TDateTime;
    begin
      t:=Now;
      DecodeDate(t,year,month,day);
      DecodeTime(t,H,M,S,MS);
      ShowMessage(IntToStr(year)+'-'+IntToStr(month)+'-'+IntToStr(day)+' '+IntToStr(H)+':'+IntToStr(M)+':'+IntToStr(S)+' '+IntToStr(MS));
    end;
      

  3.   

    procedure TForm1.Button2Click(Sender: TObject);
    begin
       edit1.Text :=formatdatetime('yyyy-mm-dd hh:n:ss:z',now) ;
    end;
      

  4.   

    用QueryPerformanceFrequency、QueryPerformanceCounter可以计算出微秒级时间数据
      

  5.   

    同意ls的
    我用这个发过脉冲信号
    (t2-t1)/c1就是时间,与你的cpu性能有关的  //取系统级时间精度:
      var
      c1:int64;
      t1,t2:int64;
      r1:double;
      begin
      QueryPerformanceFrequency(c1);//WINDOWS API 返回计数频率(Intel86:1193180)(获得系统的高性能频率计数器在一毫秒内的震动次数)
      QueryPerformanceCounter(t1);//WINDOWS API 获取开始计数值
      sleep(1000);{do...}//执行要计时的代码
      QueryPerformanceCounter(t2);//获取结束计数值
      r1:=(t2-t1)/c1;//取得计时时间,单位秒(s)
      r1:=(t2-t1)/c1*1000;//取得计时时间,单位毫秒(ms)
      r1:=(t2-t1)/c1*1000000;//取得计时时间,单位微秒
      showmessage(floattostr(r1));
      end;
      

  6.   


    cpu有个计数周期,这个周期是怎样的呢,如果两次计数不在一个周期上又当如何呢,谢谢ls的帮助
      

  7.   

    QueryPerformanceFrequency(c1);//WINDOWS API 返回cpu计数频率,获得系统的高性能频率计数器在一毫秒内的震动次数)
    同一cpu是不变的
      

  8.   

    。。
      var 
      c1:int64; 
      t1,t2:int64; 
      r1:double; 
      begin 
      QueryPerformanceFrequency(c1);//我的cpu是2913470000,就是一秒中计数器跳动这么多次。 
      QueryPerformanceCounter(t1);//开始计数值 
      sleep(1000);{do...}//执行要计时的代码 
      QueryPerformanceCounter(t2);//结束计数值 
      r1:=(t2-t1)/c1;//取得计时时间,单位秒(s)   showmessage(floattostr(r1)); //上面sleep了一秒,看看r1是不是1秒???
      end;时间很小的情况下?你以什么作参考时间啊?timer?timer本来就不能准确到10ms。
      

  9.   

    var
      c1: int64;
      t1, t2: int64;
      r1: double;
      i: integer;
      Cha: array[0..1000000] of int64;
    begin
      QueryPerformanceFrequency(c1); //我的cpu是2913470000,就是一秒中计数器跳动这么多次。
      QueryPerformanceCounter(t1); //开始计数值
      r1 := c1 / 10000; //一微妙cpu计数值
      QueryPerformanceCounter(t2);
      i := 0;
      flag := true;
      while flag do
      begin
        Application.ProcessMessages;
        QueryPerformanceCounter(t2);
        if t2 - t1 >= r1 then
        begin
          //Cha[i] := (t2 - t1);
          t1 := t2;
          inc(i);
        //添加你要执行的代码。最好这段放在一个线程里面。主线程里面单击一下或者运行什么东西就很占时间
        end;
      end;
    end;