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 ...
随机推荐
- java web项目的https配置
1.进入到jdk下的bin目录 keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat.keystore -validity ...
- Tomcat负载均衡图片显示不正常解决方法
在部署一个Tomcat玩玩的时候,发现在做nginx负载均衡时,网站显示不正常,图片会变得很大.测试了半天都没成功,最后查找资料,才发现Tomcat负载均衡时Session处理有问题,Session是 ...
- 【Flutter学习】页面布局之其它布局处理
一,概述 Flutter中拥有30多种预定义的布局widget,常用的有Container.Padding.Center.Flex.Row.Colum.ListView.GridView.按照< ...
- kubernetes session保持、容器root特权模式开启、多端口容器service 2个端口开启等设置
session保持如何在service内部实现session保持呢?当然是在service的yaml里进行设置啦. 在service的yaml的sepc里加入以下代码: sessionAffinity ...
- 【运维】使用Serv-U搭建FTP服务器
1.先安装好Serv-U,并作为系统服务安装 2.打开Serv-U,新建一个域 3.添加用户 4.解决阿里云专有网络的一个问题 遇到一个情景:需要使用Serv-U进行FTP更新软件,其中使用PASV的 ...
- VS2014:"64位调试操作花费的时间比预期要长",无法运行调试解决办法
解决步骤: 右键管理员运行命令提示符,输入IISRESERT,重启IIS即可
- leetcode上的一些分治算法
53- 思路: 95- 思路
- (61)C# 可枚举类型和迭代器
一.可枚举类型 枚举器-Enumerator 是一个只读且只能在值序列向前移动的游标 枚举器需要实现下列接口之一 System.Collections.IEnumerator System.Coll ...
- 25. 服务器性能监控之nmon工具介绍
nmon介绍: nmon是一个简单的性能监测工具,可以监测CPU.内存.网络等的使用情况. 步骤: 1.下载nmon(根据你的操作系统下载),地址 2.nmon文件部署到服务器中 3.启动nmon(注 ...
- linux 下安装与使用
一 安装 ## 先用wget下载源文件 wget http://download.redis.io/releases/redis-3.2.9.tar.gz ## 我自己建个文件夹 mkdir /usr ...