I need to parse UTC date using Delphi 6:
2013-12-24T11:05:01.000+09:00
In Delphi 7 I managed to do this with the following code:
Using
TXsDateTime
:var utcTime : TXsDateTime; localTime : TDateTime; temp : string; begin temp := '2013-12-24T00:00:00.000-02:00'; utcTime.XSToNative(temp); localTime := utcTime.AsUTCDateTime; // get time in +00:00 timezone localTime := IncHour(localTime, 9); // het time local timezone //... end;
Using
StrToDateTime
overload withTFormatSettings
:var localTime : TDateTime; temp, datetimePart : string; formatSettings : TFormatSettings; begin temp := '2013-12-24T00:00:00.000+01:00'; //init format settings GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, formatSettings); formatSettings.DateSeparator := '-'; formatSettings.ShortDateFormat := 'yyyy-MM-dd'; //parse datetime datetimePart := StringReplace(copy(temp,1,Length(temp)-10),'T',' ',[]); localTime := StrToDateTime(datetimePart, formatSettings); //get datetime in +00:00 timezone localTime := IncHour(localTime, -1*strtoint(copy(temp,Length(temp)-5,3))); localTime := IncMinute(localTime, -1*strtoint(copy(temp,Length(temp)-1,2))); //get datetime in local timezone localTime := IncHour(localTime , 9); //... end;
But in Delphi 6:
- I cannot even call
XSToNative
, as it throwsEConvertError
misplacing month and day parts of the date; and alsoTXsDateTime
does not contain definition forAsUTCDateTime
... SysUtils
does not contain definition forTFormatSettings
and consequently the overload ofStrToDateTime
I use is unavailable.
Is there anything I am missing, or what else can I use to parse this format in Delphi 6?
In the end I used
EncodeDateTime
function: