xtimes.pas

来自「《Delphi深度历险》附书源码 Delphi学习书本」· PAS 代码 · 共 44 行

PAS
44
字号
unit xTimes;

interface

uses Windows, Messages, SysUtils, Forms, Controls;

function TimeT_To_DateTime(TimeT: Longint): TDateTime;

function TimeToSecond(const H, M, S: Integer): Integer;
procedure SecondToTime(const secs: Integer; var H, M, S: Word);
function SecondToTimeStr(secs: Integer): string;

implementation

function TimeT_To_DateTime(TimeT: Longint): TDateTime;
var
  ts: TTimeStamp;
begin
  Dec(TimeT, 3600 * 8);    // still unprecise
  ts.Time := (TimeT mod 86400) * 1000;
  ts.Date := TimeT div 86400 + 719163;
  Result := TimeStampToDateTime(ts);
end;

function TimeToSecond(const H, M, S: Integer): Integer;
begin
  Result := H * 3600 + M * 60 + S;
end;

procedure SecondToTime(const secs: Integer; var H, M, S: Word);
begin
  H := secs div 3600;
  M := (secs mod 3600) div 60;
  S := secs mod 60;
end;

function SecondToTimeStr(secs: Integer): string;
var
  H, M, S: Word;
begin
 Secondtotime(secs, h, m, s);

 result := '';
 if h <> 0 then Result := result + format('%-.2d 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?