转贴他人的资料加本人注释:希望能解决该问题,呵呵~~~~~~~~
用这句启动对方时间服务:Winexec( 'C:/windows/net time ////servername /set /yes)
///////////////////////////////////////////////
PTime_Of_Day_Info = ^TTime_Of_Day_Info;
TTime_Of_Day_Info = record //获得的格式
tod_elapsedt :Integer;
tod_msecs :Integer;
tod_hours :Integer;
tod_mins :Integer;
tod_secs :Integer;
tod_hunds :Integer;
tod_timezone :LongInt;
tod_tinterval :Integer;
tod_day :Integer;
tod_month :Integer;
tod_year :Integer;
tod_weekday :Integer;
end;
function NetRemoteTOD(ServerName
WideChar; var buffer
ointer) :Integer; stdcall; external 'netapi32.dll'; //外部函数也是最关键函数
function NetApiBufferFree(buffer : Pointer) :Integer; stdcall; external 'netapi32.dll';
function TNTRemoteDateTime.GetTOD(ServerName: WideString): Integer;//获取函数
var Buffer
ointer;
Rek
Time_Of_Day_Info;
ADate, ATime FinalTime :TDateTime;
THours, TMins, TSecs, TMSecs :Word;
TYear, TMonth, TDay :Word;
begin
result:=NetRemoteTOD(PWideChar(ServerName), Buffer);
if result=0 then
begin
Rek:=PTime_Of_Day_Info(Buffer);
FServerName :=ServerName;
FElapseDt :=Rek.tod_elapsedt;
FMSecs :=Rek.tod_msecs;
FHours :=Rek.tod_hours;
FMins :=Rek.tod_mins;
FSecs :=Rek.tod_secs;
FHunds :=Rek.tod_hunds;
FTInterval :=Rek.tod_tinterval;
If Rek.tod_timezone <> -1 then
begin
FTimeZone:=Rek.tod_timezone div 60;
end
else
FTimeZone:=0;
FDay :=Rek.tod_day;
FMonth :=Rek.tod_month;
FYear :=Rek.tod_year;
FWeekDay :=Rek.tod_weekday;
ADate:=EncodeDate(FYear, FMonth, FDay);
ATime:=EnCodeTime(FHours, FMins, FSecs, FHunds);
FinalTime:=StrToDateTime(DateTimeToStr(ADate) + ' ' + TimeToStr(ATime));
FinalTime:=FinalTime - (FTimeZone / 24);
decodetime(FinalTime,THours, TMins,TSecs, TSecs);
FHours:=Integer(THours);
decodeDate(FinalTime,TYear, TMonth,TDay);
FYear:=Integer(TYear);
FMonth:=Integer(TMonth);
FDay:=Integer(TDay);
end;
NetApiBufferFree(Buffer);
end;