delphi中设置系统时间方法

时间:2024-07-01 11:35:08

procedure TMainFrm.Timer1Timer(Sender: TObject);
var

  systemtime:Tsystemtime;

  dt:TDateTime;

begin

  L_DateTime.Caption:=FormatDateTime('YYYY-MM-DD HH:SS',Now); //显示当前时间

MainFrm.Caption:=IntToStr(Timer1.Tag);

  timer1.tag:=timer1.tag+1;

  if Timer1.tag=60 then begin

     Timer1.tag := 0;

     if (PC1.ActivePage <> Page_start) then begin

        Btn_Input_FirstClick(nil);  //返回首页

     end;

  end;

if copy(L_DateTime.Caption,12,5)='02:00' then begin  //晚两点同步时间

     try

       DM.GetTime.Open;

       dt := DM.GetTimeCurrTime.Value;

       DateTimeToSystemTime(dt,systemtime);   //把Delphi的TDateTime格式转化为API的

       SetLocalTime(SystemTime);   //设置系统时间

       //GetLocalTime(SystemTime);   //读取系统时间

       //DateTime:=SystemTimeToDateTime(SystemTime);   //把API的TSystemTime格式   转化为   Delphi的TDateTime格式

     finally

     end;

  end;

end;