SoapStr2Datetime (rtl)
Function SoapStr2Datetime(const S:string):TDateTime;
Cette fonction convertie une chaîne représentant une date et heure au format SOAP en date et heure.
| Result | La date et heure représenté par la chaîne. |
| S | Une chaîne représentant une date et heure au format SOAP. |
Exemple
// Decode 1999-05-31T13:20:00.000-05:00 as datetime
//
function soapStr2Datetime(ss:string):TdateTime;
var xx:Integer; sz,sd,st:string;
begin
// ISO 8601
// http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#dateTime
// 2006-11-16T13:29:07.3389395+01:00
//
xx := Pos('T',ss);
if xx<>0 then
begin
sd := Copy(ss,1,xx-1);
st := Copy(ss,xx+1,length(ss)-xx);
end
else
if Pos(':',ss)<>0 then
begin
// only time
sd := '';
st := ss;
end
else
begin
// only date
sd := ss;
st := '';
end;
//
sz := '';
if (st<>'') then
begin
// Timezone part
xx := Pos('Z',st);
if xx<>0 then
begin
sz := 'Z'; //timezone part
st := Copy(st,1,xx-1);
end;
xx := Pos('-',st);
if xx<>0 then
begin
sz := Copy(st,xx,length(st)-xx+1);
st := Copy(st,1,xx-1);
end;
xx := Pos('+',st);
if xx<>0 then
begin
sz := Copy(st,xx,length(st)-xx+1);
st := Copy(st,1,xx-1);
end;
end;
// UTC Result
Result := soapStr2Date(sd)+soapStr2Time(st)-soapTimezone2Offset(sz);
//
if (st<>'')or(sz<>'') then Result := GetLocalTime(Result);
end;
Alias de cette fonction :
Voir aussi: