Einzelnen Beitrag anzeigen

Benutzerbild von implementation
implementation

Registriert seit: 5. Mai 2008
940 Beiträge
 
FreePascal / Lazarus
 
#3

AW: VarToDateTime mit englischem Datum

  Alt 14. Jan 2012, 21:35
Zur Not mach's so:
Delphi-Quellcode:
function ConvertDate(const str: string): TDate;
var i: byte; d, m, y: word; mn: string;
const months: array[1..12] of string = ('jan','feb','mar','apr','may',
               'jun','jul','aug','sep','oct','nov','dec');
  procedure Next;
  begin
    Inc(i);
  end;
  function GetNum: word;
  begin
    Result := 0;
    while str[i] in ['0'..'9'] do begin
      Result := Result*10 + Ord(str[i]) - Ord('0');
      Next;
    end;
  end;
  procedure SkipWhite;
  begin
    while str[i] in [#9,#32] do Next;
  end;
  function GetName: string;
  begin
    Result := '';
    while str[i] in ['a'..'z','A'..'Z'] do begin
      if str[i] in ['a'..'z'] then
        Result := Result + str[i]
      else Result := Result + Chr(Ord(str[i])-Ord('A')+Ord('a'));
      Next;
   end;
  end;
begin
  i := 1;
  d := GetNum;
  SkipWhite;
  mn := GetName;
  SkipWhite;
  y := GetNum;
  for i := 1 to 12 do
    if months[i]=mn then
      m := i;
  if not TryEncodeDate(y,m,d,result) then
    raise EConvertError.Create('Invalid date');
end;

Geändert von implementation (14. Jan 2012 um 21:56 Uhr)
  Mit Zitat antworten Zitat