zoukankan      html  css  js  c++  java
  • Delphi使用XmlHttp获取时间

    uses ComObj, DateUtils;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      XmlHttp: Variant;
      datetxt : String;
      DateLst : TStringList;
      mon: String;
      timeGMT,GetNetTime:TDateTime;
    begin
        XmlHttp := CreateOleObject('Microsoft.XMLHTTP');
        XmlHttp.Open( 'Get', 'http://www.baidu.com/', False);
        XmlHttp.send; 
        datetxt :=XmlHttp.getResponseHeader('Date');
        datetxt := Copy(datetxt,Pos(',',datetxt)+1,100);
        datetxt := StringReplace(datetxt,'GMT','',[]);
        datetxt := Trim(datetxt);
        DateLst := TStringList.Create;
        while Pos(' ',datetxt)>0 do
        begin
            DateLst.Add(Copy(datetxt,1,Pos(' ',datetxt)-1)) ;
            datetxt := Copy(datetxt,Pos(' ',datetxt)+1,100);
        end ;
        DateLst.Add(datetxt) ; 
        if DateLst[1] = 'Jan' then
            mon := '01'
        else if DateLst[1] = 'Feb' then
            mon := '02' 
        else if DateLst[1] = 'Mar' then
            mon := '03'
        else if DateLst[1] = 'Apr' then
            mon := '04'
        else if DateLst[1] = 'Mar' then
            mon := '05' 
        else if DateLst[1] = 'Jun' then
            mon := '06'
        else if DateLst[1] = 'Jul' then
            mon := '07'
        else if DateLst[1] = 'Aug' then
            mon := '08'
        else if DateLst[1] = 'Sep' then
            mon := '09'
        else if DateLst[1] = 'Oct' then
            mon := '10'
        else if DateLst[1] = 'Nov' then
            mon := '11'
        else if DateLst[1] = 'Dec' then
            mon := '12' ; 
        timeGMT := StrToDateTime(DateLst[2]+'-'+mon+'-'+DateLst[0]+' '+ DateLst[3]);
        GetNetTime := IncHour(TimeGMT,8); 
        self.Caption := FormatDateTime('yyyy年mm月dd日 HH:NN:SS',GetNetTime) ;
    end;

    http://www.lsworks.net/article/20.html

  • 相关阅读:
    正则表达式(Python3-re模块示例)
    format函数之几种常规用法
    元组的拆包
    Python3魔术方法实现一摞卡牌
    Python字典的常见操作
    70. Climbing Stairs(js)
    69. Sqrt(x)(js)
    68. Text Justification(js)
    67. Add Binary(js)
    66. Plus One(js)
  • 原文地址:https://www.cnblogs.com/findumars/p/4998996.html
Copyright © 2011-2022 走看看