delphi 时间差
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, System.DateUtils,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
DateTimePicker1: TDateTimePicker;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetSubDateTime(S1, S2:string): string;
var
T1, T2: TDateTime;
D, H, M, S: Integer;
Value: Int64;
begin
T1 := StrToDateTime(S1);
T2 := StrToDateTime(S2);
Value := SecondsBetween(T1, T2);
D := Value div SecsPerDay;
H := Value mod SecsPerDay div SecsPerHour;
M := Value mod SecsPerDay mod SecsPerHour div SecsPerMin;
S := Value mod SecsPerDay mod SecsPerHour mod SecsPerMin;
result := Format('%.2d天 %.2d小时%.2d分钟%.2d秒',[D, H, M, S]);
end;
procedure TForm1.Button1Click(Sender: TObject);
var S1,s2:string;
T1, T2: TDateTime;
begin
S1 := '2015-09-23 15:44:50';
T1 := StrToDateTime(s1) + 12/24;
s2 := DateTimeToStr(t1);
//S2 := '2015-09-23 16:47:51';
Edit1.Text := s2
//GetSubDateTime(S1,s2);
end;
end.