首页  编辑  

取得服务器的时间

Tags: /超级猛料/Date.Time.时间和日期/   Date Created:
NTRemote DateTime:
部分关键代码:
 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 :PWideChar;
                       var buffer :pointer) :Integer; stdcall; external 'netapi32.dll';
function NetApiBufferFree(buffer : Pointer) :Integer; stdcall; external 'netapi32.dll';
function TNTRemoteDateTime.GetTOD(ServerName: WideString): Integer;
var Buffer     :pointer;
   Rek        :PTime_Of_Day_Info;
   ADate      :TDateTime;
   ATime      :TDateTime;
   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;