首页 > 其他分享 >将TDateTime值分解为小时、分钟、秒和毫秒,以及计算时间差

将TDateTime值分解为小时、分钟、秒和毫秒,以及计算时间差

时间:2023-04-11 20:00:11浏览次数:34  
标签:Hour Min IntToStr 时间差 毫秒 TDateTime Year Month Day

 

将时间日期分解

procedure TForm1.Button1Click(Sender: TObject);
var
  Present: TDateTime;
  Year, Month, Day, Hour, Min, Sec, MSec: Word;
 begin
  Present:= Now;
  SysUtils.DecodeDate(Present, Year, Month, Day);
  Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
    + IntToStr(Month) + ' of Year ' + IntToStr(Year);
  SysUtils.DecodeTime(Present, Hour, Min, Sec, MSec);
  Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
    + IntToStr(Hour);
end;

时间差

procedure TForm1.Button1Click(Sender: TObject);
var
  Year, Month, Day, Hour, Min, Sec, MSec: Word;
  Hour1, Min1, Sec1, MSec1: Word;
 begin
  DecodeTime(now, Hour, Min, Sec, MSec);
  DecodeTime(DateTimePicker1.Time,Hour1, Min1, Sec1, MSec1);
  Edit1.Text:=inttostr((hour*3600 + min*60 + sec)-(hour1*3600 + min1*60 + sec1)) ;
end;

 

标签:Hour,Min,IntToStr,时间差,毫秒,TDateTime,Year,Month,Day
From: https://www.cnblogs.com/sixty-five/p/17307469.html

相关文章