您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi中HTTP请求返回日期转TDateTime

时间:2011/9/3 15:30:02 点击:

  核心提示:function BuffTextEqualAsm(const Str1, Str2: PChar; MaxLen: Cardinal): Boolean; assembler;asm PUSH ED...

function BuffTextEqualAsm(const Str1, Str2: PChar; MaxLen: Cardinal): Boolean; assembler;
asm
   PUSH EDI
   PUSH ESI
   PUSH EBX
   MOV EDI,EDX
   MOV ESI,EAX
   MOV EBX,ECX
   XOR EAX,EAX
   OR ECX,ECX
   JE @@T
   REPNE SCASB
   SUB EBX,ECX
   MOV ECX,EBX
   MOV EDI,EDX
   XOR EDX,EDX
@@1:
   REPE CMPSB
   JE @@T
   MOV AL,[ESI-1]
   CMP AL,'a'
   JB @@2
   CMP AL,'z'
   JA @@2
   SUB AL,20H
@@2:
   MOV DL,[EDI-1]
   CMP DL,'a'
   JB @@3
   CMP DL,'z'
   JA @@3
   SUB DL,20H
@@3:
   SUB EAX,EDX
   JE @@1
@@F:
   xor EAX,EAX
   jmp @@E
@@T:
   mov EAX,1
@@E:
   POP EBX
   POP ESI
   POP EDI
end;

 

function IndexedWithToken(const Src: String;const Index: Integer;Token:String = ','): String;
var
  P, Start    : PChar;
  tkLength    : Integer;
  LocalIndex  : Integer;
begin
  Result      := '';
  LocalIndex       := 1;
  tkLength    :=  Length(Token);
  P           :=  Pointer(Src);
  Start     := P;
  if Index <= 0 then Exit;

  if P  <>  nil then begin
    while P^  <>  #0 do
      begin
        while Not ((P^ In [#0]) or BuffTextEqualAsm(P,Pointer(Token),tkLength)) do Inc(P);
        if P <> Start then
          begin
            if LocalIndex = Index then
              begin
                SetString(Result, Start, Integer(P - Start));
                Exit;
              end;
          end;
        if P^ = #0 then break;
        Inc(LocalIndex);
        Inc(P,tkLength);
        Start := P;
      end;
  end;
  if P <> Start then
    begin
      if LocalIndex = Index then
        begin
          SetString(Result, Start, Integer(P - Start));
          Exit;
        end;
    end;
end;

function GetValidDateTime(Datestr: string): TDateTime;
var
  Mon: string;
  i: Integer;
  st: string;
const
  MyMonth: array[1..12] of string=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec');
begin
  Mon := IndexedWithToken(Datestr,3,' ');
  st := IndexedWithToken(Datestr,4,' ') + '-';
  for i := 1 to 12 do
    if CompareText(Mon,MyMonth[i]) = 0 then
    begin
      st := st + IntToStr(i);
      break;
    end;
  st := st + '-'+ IndexedWithToken(Datestr,2,' ') + ' '+IndexedWithToken(Datestr,5,' ');
  result := StrToDateTime(st) + 1/3;
end;

作者:不得闲 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章 技术支持:深圳市麟瑞科技有限公司(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 粤ICP备10103342号-1