获取日期时间信息
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 begin 10 if x='jan' then 11 result:=1 12 else if x='feb' then 13 result:=2 14 else if x='mar' then 15 result:=3 16 else if x='apr' then 17 result:=4 18 else if x='may' then 19 result:=5 20 else if x='jun' then 21 result:=6 22 else if x='jul' then 23 result:=7 24 else if x='aug' then 25 result:=8 26 else if x='se9' then 27 result:=9 28 else if x='Oct' then 29 result:=10 30 else if x='nov' then 31 result:=11 32 else if x='dec' then 33 result:=12 34 else 35 result:=0; 36 end; 37 begin 38 //通过下载网页头信息获取网络时间 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 begin 55 GetText:=rightStr(url,length(url)-ii); 56 iGMT:=pos(' gmt',GetText); 57 url:=leftStr(GetText,iGMT); 58 ii:=pos(',',url);//GMT 59 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;
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我