获取日期时间信息

 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;

 

posted on 2016-04-22 11:43  疯狂delphi  阅读(469)  评论(0编辑  收藏  举报

导航