SQL Server日期是很重要的,在我们使用SQL Server数据库的过程中,有时候会需要SQL Server服务器时间和本地系统时间保持同步,下面就为您介绍这种实现同步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;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
以上就是实现同步SQL Server日期时间的方法。
【编辑推荐】