delphi 时间
DELPHI高精度计时方法
//取毫秒级时间精度(方法一):
var
t1,t2:int64;
r1:int64;
begin
t1:=GetTickCount;//获取开始计数 WINDOWS API
sleep();{do...}//执行要计时的代码
t2:=GetTickCount;//获取结束计数值
r1:=t2-t1;//取得计时时间,Y\`国4~络(}.u_%t"hV单位毫秒(ms)
showmessage(inttostr(r1));
end; //取毫秒级时间精度(方法二):
//use DateUtils;//引用DateUtils单位
var
t1,t2:tdatetime;
r1:int64;
begin
t1:=now();//获取开始计时时间
sleep();{do...}//执行要计时的代码
t2:=now();//获取结束计时时间
r1:=SecondsBetween(t2,t1);//取得计时时间,D6k=+W的TsoUbP育_II单位秒(s)
r1:=MilliSecondsBetween(t2,t1);//取得计时时间, 单位毫秒(ms)
showmessage(inttostr(r1));
end; //注:以上两种方式经本人测试好像只能产生0.01秒的计时精度 //取系统级时间精度:
var
c1:int64;
t1,t2:int64;
r1:double;
begin
QueryPerformanceFrequency(c1);//WINDOWS API 返回计数频率(Intel86:1193180)(获得系统的高性能频率计数器在一毫秒内的震动次数)
QueryPerformanceCounter(t1);//WINDOWS API 获取开始计数值
sleep();{do...}//执行要计时的代码
QueryPerformanceCounter(t2);//获取结束计数值
r1:=(t2-t1)/c1;//取得计时时间, 单位秒(s)
r1:=(t2-t1)/c1*;//取得计时时间,单位毫秒(ms)
r1:=(t2-t1)/c1*;//取得计时时间,单位微秒
showmessage(floattostr(r1));
end;
delphi 延迟函数
//延迟函数:方法一
procedure delay(msecs:integer);
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(msecs);
while (msecs > ) and (MsgWaitForMultipleObjects(, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs := Tick - GetTickcount;
end;
finally
CloseHandle(Event);
end; //延迟函数:方法二
procedure Delay(dwMilliseconds:DWORD);//Longint
var
iStart,iStop:DWORD;
begin
iStart := GetTickCount;
repeat
iStop := GetTickCount;
Application.ProcessMessages;
until (iStop - iStart) >= dwMilliseconds;
end; 方法三
procedure delay(msecs:integer); //延迟函数 比sleep好
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(msecs);
while (msecs > ) and (MsgWaitForMultipleObjects(, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs := Tick - GetTickcount;
end;
finally
CloseHandle(Event);
end;
一段代码执行消耗的时间
关键是用到一个库函数GetTickCount 【函数名】 GetTickCount 【返回值】 Long,以毫秒为单位 通常用来计算某个操作所使用的时间:
var: start_time : LONG; stop_time:LONG; begin:
start_time :=GetTickCount; 调用接口操作
stop_time :=GetTickCount; ShowMessage( IntToStr(stop_time - art_time));
end;
获取系统时间
var
DateTime:TDateTime;
i:string;
begin
DateTime:=now;
i:=DateToStr(DateTime)+' '+TimeToStr (DateTime);
lable1.caption:=i; FormatDateTime('hh:nn:ss',Now());
FormatDateTime('yyyy年mm月dd日 hh时nn分ss秒zzzz',now()); var
DateTime:TDateTime;
i:string;
ct:TSystemTime;
begin
DateTime:=now;
i:=DateToStr(DateTime)+' '+TimeToStr (DateTime);
//Label1.caption:=i;
//Label1.caption:=FormatDateTime('yyyy年mm月dd日 hh时nn分ss秒zz',now());
//GetSystemTime();
//GetLocalTime(ct);
//Label1.caption:=GetSystemTime(ct);//FormatDateTime('yyyy年mm月dd日 hh时nn分ss秒zz',GetSystemTime(ct));
end;
delphi 时间的更多相关文章
- delphi 时间格式操作
FormatDateTime('yyyy-mm-dd hh:nn:ss',Now) FormatDateTime('hh:mm:ss:zz',Now) if (TimeOf(now) < pub ...
- Delphi 时间耗时统计
处理事情: 数据处理过程中,速度很慢,无法准确定位分析是DB问题还是客户端处理问题,所以增加计时统计日志: Delphi计时首次使用,查阅资料,予以记录: var BgPoint, EdPoind: ...
- delphi时间日期函数
unit DateProcess; interface const DayOfWeekStrings: ..] of String = ('SUNDAY', 'MONDAY', 'TUESDAY', ...
- Delphi 时间函数:关于时间精确的几个函数和方法
//取毫秒级时间精度(方法一): var t1,t2:int64; r1:int64; begin t1:=GetTickCount;//获取开始计数 WINDOWS API sleep(1000); ...
- 怎么使用Delphi获取当前的时间,精确到毫秒
先介绍一个可能比较常用的方法,获取当前时间 var datetime: string; begin datetime:= FormatDateTime('yyyy-mm-dd hh:mm:ss', N ...
- Delphi DateUtils时间单元
Uses DateUtils //时间单元,非常有用. 记得引用这个单元,不然不能用. CompareDate 比较两个日期时间值日期部分的大小 CompareDateTime 比较两个日期时间值的大 ...
- delphi 最全日期格式_DateUtils时间单元说明
DateUtils时间单元说明 CompareDate 函数 比较两个日期时间值日期部分的大小 CompareDateTime 函数 比较两个日期时间值的大小 CompareTime 函数 比较两个日 ...
- Delphi日期时间 UNIX
Delphi日期时间,就是常见的 2014-05-02 10:37:35 --------------------------------------------------------------- ...
- Delphi的时间处理
这几天因为自己要学习编写一个小程序中要用到一些时间处理.就在网上搜集一些教材学习到一般的应用,做个笔记,加深印象. 用上Delphi中相应的函数,Delphi的时间处理起来还是很容易的. Delphi ...
随机推荐
- 【架构】Linux的架构(architecture)
最内层是硬件,最外层是用户常用的应用,比如说firefox浏览器,evolution查看邮件,一个计算流体模型等等.硬件是物质基础,而应用提供服务.但在两者之间,还要经过一番周折. 还记得Linux启 ...
- vue实现前后台交互
首先需要前台先安装一个包 cnpm install axios --save 第二还需要解决跨域问题 在settings中添加一条中间件 MIDDLEWARE = [“corsheders.middl ...
- python--函数的返回值、函数参数的使用、名称空间与作用域、函数嵌套、函数对象
今天学习内容有函数的返回值.函数参数的使用.名称空间与作用域.函数嵌套. 下来我们一一查看. 函数的返回值 看几个栗子: def func(x): y=func() print(y) def foo( ...
- UNP学习 Unix域协议
Unix域协议并不是一个实际的协议族,它只是在同一台主机上进行客户-服务器通信时,使用与在不同主机上的客户和服务器间通信时相同的API的一种方法. 当客户和服务器在同一台主机上时,Unix域协议是这套 ...
- 第七周-scrum meeting
第一部分ScrumMeeting 每个人的工作:其他人:(请填写自己的任务) 成员 任务 ISSUE链接 本周已完成的工作 本周计划完成的工作 工作中遇到的困难 关玉娇 负责登录注册界面的设计与实现 ...
- 57、saleforce学习笔记(四)
List类 List在这里就是一个类 List<String> lists = new String[]{'1','3'}; List<String> list1 = new ...
- (动态改变数据源遇到的问题)sqlserver2012:No Dialect mapping for JDBC type: -9解决方案
public class MySQLServerDialect extends SQLServerDialect { public MySQLServerDialect() { super(); re ...
- HP Server BIOS实验报告
原文链接http://www.hpiss.com/3924.html 注意:红色字体为HP手册中查找到的资源,及个人感觉应该注意的一些信息,个人翻译的也为红字体,网络中自行查找到的资源,以及询问各位师 ...
- python学习笔记:数据类型——数字、字符串、元祖、字典
计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要定义不同的数 ...
- PAT甲级——A1144 TheMissingNumber【20】
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...