在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
相关资料: http://www.360doc.com/content/12/0628/09/7662927_220905393.shtml //delphi 求两个时间差 https://blog.csdn.net/zengcong2013/article/details/46369523 //delphi “div”、“mod”、“\”除法运算符的区别与使用方法 http://www.delphitop.com/html/shijian/3220.html //01天 01:01:02输出方式
1 procedure TForm1.Button8Click(Sender: TObject); 2 var 3 sd, nd: TDateTime; 4 randid: string; 5 begin 6 sd := StrtoDatetime ('1981/08/08 00:00:00'); 7 nd := Now; 8 Memo1.Clear; 9 Memo1.Lines.Add('开始测试时间差:'); 10 Memo1.Lines.Add('起始时间:1981-08-08 00:00:00'); 11 Memo1.Lines.Add('终止时间:'+DateTimeToStr(nd)); 12 Memo1.Lines.Add('年:'+IntToStr(YearsBetween(sd, nd))); 13 Memo1.Lines.Add('月:'+IntToStr(MonthsBetween(sd, nd))); 14 Memo1.Lines.Add('周:'+IntToStr(WeeksBetween(sd, nd))); 15 Memo1.Lines.Add('日:'+IntToStr(DaysBetween(sd, nd))); 16 Memo1.Lines.Add('时:'+IntToStr(HoursBetween(sd, nd))); 17 Memo1.Lines.Add('分:'+IntToStr(MinutesBetween(sd, nd))); 18 Memo1.Lines.Add('秒:'+IntToStr(SecondsBetween(sd, nd))); 19 Memo1.Lines.Add(#13) ; 20 Memo1.Lines.Add('以秒差为例生成随机数: '); 21 randid := IntToStr(SecondsBetween(sd, nd))+ 22 IntToStr(random(9))+ 23 IntToStr(random(9))+ 24 IntToStr(random(9))+ 25 IntToStr (random(9));//呵呵,很笨的方法。 26 Memo1.Lines.Add(randid); 27 end;
1 function GetSubDateTime(S1, S2:string): string; 2 var 3 T1, T2: TDateTime; 4 D, H, M, S: Integer; 5 Value: Int64; 6 begin 7 T1 := StrToDateTime(S1); 8 T2 := StrToDateTime(S2); 9 Value := SecondsBetween(T1, T2); 10 D := Value div SecsPerDay; 11 H := Value mod SecsPerDay div SecsPerHour; 12 M := Value mod SecsPerDay mod SecsPerHour div SecsPerMin; 13 S := Value mod SecsPerDay mod SecsPerHour mod SecsPerMin; 14 result := Format('%.2d天 %.2d:%.2d:%.2d',[D, H, M, S]); 15 end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论