1 function netDate:string; 2 var//网页头获取日期时间信息 3 v:Variant; 4 url,GetText:string; 5 dd,mm,yy:string; 6 ii,iGMT:integer; 7 TT:Tdate; 8 function MonthStr(x:string):integer; 9 begin10 if x='jan' then11 result:=112 else if x='feb' then13 result:=214 else if x='mar' then15 result:=316 else if x='apr' then17 result:=418 else if x='may' then19 result:=520 else if x='jun' then21 result:=622 else if x='jul' then23 result:=724 else if x='aug' then25 result:=826 else if x='se9' then27 result:=928 else if x='Oct' then29 result:=1030 else if x='nov' then31 result:=1132 else if x='dec' then33 result:=1234 else35 result:=0;36 end;37 begin38 //通过下载网页头信息获取网络时间39 v:=createoleobject('Microsoft.XMLHTTP');//创建OLE对象40 url:='http://www.163.com';41 v.Open('Get',url,False,'','');42 v.setRequestHeader('If-Modified-Since','0');43 v.setRequestHeader('Cache-Control', 'no-cache');44 v.setRequestHeader('Connection', 'close');45 v.Send;46 If v.ReadyState<>4 Then Exit;47 48 ii:=0;49 GetText:=v.getAllResponseHeaders;50 iGMT:=pos('GBK',GetText);51 If iGMT>0 Then//网页下载成功52 url:=lowerCase(GetText);53 ii:=pos('date:',url);54 If ii>0 Then begin55 GetText:=rightStr(url,length(url)-ii);56 iGMT:=pos(' gmt',GetText);57 url:=leftStr(GetText,iGMT);58 ii:=pos(',',url);//GMT59 GetText:=rightStr(url,length(url)-ii);//'24 jan 2013 08:17:18'60 url:=trim(GetText);61 url:=leftStr(url,length(url)-9);//'24 jan 2013'62 ii:=pos(' ',url);63 dd:=trim(leftStr(url,ii-1));//日64 url:=trim(rightStr(url,length(url)-ii));65 ii:=pos(' ',url);66 mm:=trim(leftStr(url,ii-1));//月67 yy:=trim(rightStr(url,length(url)-ii));//年68 url:=yy+'-'+inttostr(MonthStr(mm))+'-'+dd;69 70 TT:=strtoDate(url);71 result:=FormatDateTime('yyyy-mm-dd',TT);72 End;73 end;