zoukankan      html  css  js  c++  java
  • 获取日期时间信息

     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;
  • 相关阅读:
    Python os模块简单应用
    requests获取源代码时中文乱码问题
    python 正则表达式findall和search用法
    linux source路径配置 省掉每次source的烦恼
    mstar屏参调试说明
    Mstar supernova方案调试笔记-001
    NonOS方案屛参的TOTAL和PLL SET值的设置
    supernova系统 Mrsv 简介笔记
    【工作随笔】Javascript 日期获取封装组件
    如何理解springboot中,mapper接口的实现类由持久层框架进行创建,而不由spring创建?
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/5420677.html
Copyright © 2011-2022 走看看