做一个时间服务器:
1.server:D6的自带控件TimeServer
2.client:D6控件IdTime,配置IdTime
---------------------------
server的代码:
procedure TForm1.serverExecute(AThread: TIdPeerThread);
var
Present: TDateTime;
timestr,months,days,hours,mins,secs,msecs:string;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
DecodeTime(Present, Hour, Min, Sec, MSec);
//////
if month<10 then
months:='0'+inttostr(month) else
months:=inttostr(month);
if day<10 then
days:='0'+inttostr(day) else
days:=inttostr(day);
if hour<10 then
hours:='0'+inttostr(hour) else
hours:=inttostr(hour);
if min<10 then
mins:='0'+inttostr(min) else
mins:=inttostr(min);
if sec<10 then
secs:='0'+inttostr(sec) else
secs:=inttostr(sec);
if msec<100 then
begin
msecs:='0'+inttostr(msec);
if msec<10 then
msecs:='00'+inttostr(msec);
end
else
msecs:=inttostr(msec);
timestr :=IntToStr(Year)+Months+Days+Hours+Mins+secs+msecs;
with athread.Connectiondo
begin
WriteLn(timestr);
Disconnect ;
end;
end;
client:
用 time:=datetostr() 和time:=timetostr() 得到服务器的时间
搞定!