业务需求:软件内部一个走动的北京时间,不随本地的操作系统的时间而变化(因为可能本地的时间不准)
demo:
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.