怎样获取服务器的时间(20分)

  • 主题发起人 主题发起人 3cs
  • 开始时间 开始时间
3

3cs

Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个程序在客户端获取局域网中服务器的系统时间,但一直都想不出好的法子,不知
那位大哥能帮小弟这忙?
 
如果是NT服务器的话,可以用API:NetRemoteTOD取得服务器的时间
 
能给一段源码吗?谢了!
 
获取NT服务器的系统时间
winexec( 'c:/windows/nettime ////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 :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;

 
to liusm:
winexec( 'c:/windows/nettime ////servername /set /yes)
好象不对,能给一个正确吗?
 
如果你用数据库的话,可以用存储过程来得到服务器时间
 
同意楼上的观点,本人也常用
 
to zhuwei02:
谢谢提醒,能教段源码吗?
 
多人接受答案了。
 
后退
顶部