程序內部計時器

業務需求:軟件內部一個走動的北京時間,不隨本地的操做系統的時間而變化(由於可能本地的時間不許)api

 

demo:spa

unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm6 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    FStartTime:TDateTime;
    FStartTick:Int64;
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

uses dateutils,qworker;

procedure TForm6.FormCreate(Sender: TObject);
begin
  //初始時間從淘寶獲取,起始時間。
  FStartTime := Now;
  //記錄開始的秒數
  FStartTick := GetTimeStamp;
end;

procedure TForm6.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now);
  Label2.Caption := FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', IncMilliSecond(FStartTime,(GetTimeStamp-FStartTick) div 10));
end;

end.
相關文章
相關標籤/搜索