怎么获取服务器的时间,不从数据库中获取,并在本机(客户机)修改时间和服务器相同?送分(50分)

  • 主题发起人 主题发起人 cjm
  • 开始时间 开始时间
我可不想要
Winexec('net time //servername /set /yes...').....

用程序来实现
 
[BLUE]
获取时间:
var
ServerDateTime:TDateTime;
begin
Query1.Active:=False;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT GETDATE() AS TheDateTime');
Query1.Active:=True;
ServerDateTime:=Query1.FieldByName('TheDateTime').AsDateTime;
end;
[/BLUE][GREEN]
设置客户系统时间:
if SetPCSystemTime(ServerDateTime) then
MessageBox(Handle,'系统时间设置成功!','提示框',MB_OK+MB_ICONINFORMATION);

function SetPCSystemTime(tDati: TDateTime): Boolean;
var
tSetDati: TDateTime;
vDatiBias: Variant;
tTZI: TTimeZoneInformation;
tST: TSystemTime;begin
GetTimeZoneInformation(tTZI);
vDatiBias := tTZI.Bias / 1440;
tSetDati := tDati + vDatiBias;
with tST do
begin
wYear := StrToInt(FormatDateTime('yyyy', tSetDati));
wMonth := StrToInt(FormatDateTime('mm', tSetDati));
wDay := StrToInt(FormatDateTime('dd', tSetDati));
wHour := StrToInt(FormatDateTime('hh', tSetDati));
wMinute := StrToInt(FormatDateTime('nn', tSetDati));
wSecond := StrToInt(FormatDateTime('ss', tSetDati));
wMilliseconds := 0;
end;
SetPCSystemTime := SetSystemTime(tST);
end;
[/GREEN]
 
接受答案了.
 
后退
顶部