我正在使用一个webservice/soap并为clientdataset加载XML表,我有一个节点,日期采用以下格式:
2014-01-01T00:00:00.0000000-02:00
正在尝试将这种类型的数据转换为区域我的类型,我正在使用这个:
class function TDateConvert.DateTimeFromIso8601(const Value: string): TDateTime;
begin
with TXSDateTime.Create() do
try
XSToNative(value); // convert from WideString
Result := AsDateTime; // convert to TDateTime finally
finally
Free();
end;
end;
我得到了,但是日期出错了,使用上面的示例而不是返回 01/01/2014 31/12/2013 正在返回,这是巴西使用的日期格式 (dd/MM/YYYY)。
我该如何解决这个问题?这与我的区域设置(巴西)有关?
编辑
我必须使用来自 IdGlobalProtocols的函数时区偏差来更正日期,请按照下面的函数来帮助某人:
class function TDateConvert.DateTimeFromIso8601(const Value: string): TDateTime;
begin
with TXSDateTime.Create() do
try
XSToNative(value); // convert from WideString
Result := AsDateTime+TimeZoneBias; // convert to TDateTime finally with sum of timezone bias
finally
Free();
end;
end;
您的时间部分有UTC -02:00
,当时间转换为本地时间时,您的日期最终是前一天。