• 获取日期时间信息


     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;
  • 相关阅读:
    VS调试Libevent流程
    Lua require搜索路径指定方法
    关于“无法定位程序输入点gzdirect于动态链接库zlib1.dll”的问题
    poj 1737 Connected Graph
    迭代器挺好用的
    The Balance of the World Aizu
    Country Road Aizu
    牛客小白月赛4 C 病菌感染
    牛客小白月赛4 A 三角形
    老子的全排列呢
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/5420677.html
Copyright © 2020-2023  润新知