1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
function DecodeUnixTextDateTime(const TextDate: string; var DateHeure: TDateTime): Boolean;
const
Months: array[1..12] of string = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var
St: string;
I, AYear, AMonth, ADay: Integer;
Heure: TDateTime;
List: TStringList;
begin
Result:= True;
//-- Jour
St:= SeekItem(TextDate, 1, '-');
if not TryStrToInt(St, ADay)
then Exit(False);
//-- Mois
List := TStringList.Create;
for I:= Low(Months) to High(Months) do
List.Add(Months[I]);
St:= SeekItem(TextDate, 2, '-');
AMonth:= List.IndexOf(St);
List.Clear;
List.Free;
if (AMonth = -1)
then Exit(False);
end;
//-- Année
St:= '20'+Copy(TextDate, 8, 2);
if not TryStrToInt(St, AYear)
then Exit(False);
//-- Heure
St:= Copy(TextDate, 10, Length(TextDate)-14);
if not TryStrToTime(St, Heure)
then Exit(False);
end;
try
DateHeure:= DateOf(EncodeDate(AYear, AMonth, ADay))+TimeOf(Heure);
except
on e: Exception do begin
Exit(False);
end;
end;
end; |
Partager