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

  • 相关阅读:
    模板学习系列(一)tuple
    apue读书笔记第十章
    在亚马逊上关于设计模式的一个评论
    编程珠玑笔记第12章习题
    编程珠玑第14章
    C#,.Net经典面试题目及答案
    sql where 1=1和 0=1 的作用(junyuz)
    快速排序算法
    一道面试题(C#实现了超大整数的加减乘法运算)
    数据结构实验之链表一:顺序建立链表
  • 原文地址:https://www.cnblogs.com/findumars/p/4998996.html
Copyright © 2011-2022 走看看