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 ...
随机推荐
- UNP学习第13章 守护进程和inetd超级服务器
Unix系统中的syslogd守护进程通常由某个系统初始化脚本启动,而且在系统工作期间一直运行. 源自Berkeley的syslogd实现在启动时执行以下步骤. (1)读取配置文件.通常为/etc/s ...
- mybatis plus generator工具集成(一)
参数配置文档 配置分两步 1.添加依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId> ...
- POJ 3904 (莫比乌斯反演)
Stancu likes space travels but he is a poor software developer and will never be able to buy his own ...
- Redis入门很简单之二【常见操作命令】
Redis入门很简单之二[常见操作命令] 博客分类: NoSQL/Redis/MongoDB redisnosql缓存 Redis提供了丰富的命令,允许我们连接客户端对其进行直接操作.这里简单介绍一 ...
- python笔试做错的题目
a = [1,2,3] b = a print(id(a),id(b),a == b) print(a,b) b = b + [1,2,3] print(a,b) print(id(a),id(b), ...
- 3、jQuery面向对象
1.首先介绍callback.js对ajax进行了封装 function ajaxFunction(){ var xmlHttp; try{ // Firefox, Opera 8.0+, Safar ...
- Missing artifact net.sf.json-lib:json-lib:jar:2.4
Missing artifact net.sf.json-lib:json-lib:jar:2.4 出现上述这种错误就是JAR没有引入进来 这时候发现是因为JDK版本的问题,所以需要在加一句 < ...
- 搭建RAID10(5块硬盘)过程并模拟其中一块硬盘损坏
首先:RAID 10,实际是将RAID 0和RAID 1标准结合的产物,在连续地以位或字节为单位分割数据并且并行读/写多个磁盘的同时,为每一块磁盘作磁盘镜像进行冗余.它的优点是同时拥有RAID 0的超 ...
- Java对象finalize()方法
Java提供了一种在对象即将被销毁时执行资源释放的方法.在Java中创建对象,但是不能销毁对象.JVM运行一个称为垃圾收集器的低优先级特殊任务来销毁不再引用的所有对象. 垃圾回收器给我们一个机会,在对 ...
- dcoker镜像的分层
镜像分层的好处:复用节省磁盘空间,相同的内容只需加载一份到内存 修改dockerfile之后,再次构建速度加快 docker优化: 1.尽可能地选择体积小的linux发行版,比如alpine 2.尽可 ...