Delphi(程序人生)

Delphi Programer DoubleCat

导航

同步SQL_Server的日期时间

//同步SQL_Server服务器时间日期的过程
procedure TDM.SynchronizationSQLServerDateTime();
var
  TheServerDateTime:TDateTime;//定义服务器时间
  TheLocalDateTime:_SystemTime;//定义本地系统时间 引用 windows
  Year,Month,Day:Word;//定义年月日
  Hour,Min,Sec,MSec:Word;//定义时分秒毫秒
begin
  with CommonQuery do begin
       SQL.Clear;
       SQL.Add('select GetDate() as 服务器时间');
       Open;
       TheServerDateTime := FieldByName('服务器时间').AsDateTime;
  end;
  DecodeDate(TheServerDateTime,Year,Month,Day);//分解服务器年月日
  DecodeTime(TheServerDateTime,Hour,Min,Sec,MSec);//分解服务器时间
  //-------设定本地系统时间
  TheLocalDateTime.wYear:=Year;
  TheLocalDateTime.wMonth:=Month;
  TheLocalDateTime.wDay:=Day;
  TheLocalDateTime.wHour:=Hour;
  TheLocalDateTime.wMinute:=Min;
  TheLocalDateTime.wMilliseconds:=MSec;
  SetlocalTime(TheLocalDateTime);//更改本地系统时间 
end;

posted on 2010-07-15 23:48  DoubleCat  阅读(363)  评论(0编辑  收藏  举报