By default, ISOToDateTime
doesn't accept time zones. There is an overload method that you can pass the TTimeZoneMode
, which you specify how time zone must be treated:
class function ISOToDateTime(const Value: string; TimeZoneMode: TTimeZoneMode): TDateTime; overload;
TTimeZoneMode = (Error, Ignore, AsUTC, AsLocal);
Default is Error
, which means if the date has timezone information, a error will be raised. You can use any of the other options:
Ignore
will simply strip out the time zone and ignore it.
AsUTC
will take time zone into account and return the date/time value for you in UTC time zone.
AsLocal
will take time zone into account and return the date/time value for you in your local time zone. So, for example:
Value := TBclUtils.ISOToDateTime('2021-09-01T09:05:12+08:00', TTimeZoneMode.AsLocal);
Alternatively, you can change the global TTimeZoneMode setting, which will affect all the ISOToDateTime
operations globally:
// Affects all ISOToDateTime calls from now on
DefaultTimeZoneMode := TTimeZoneMode.AsLocal;
Value := TBclUtils.ISOToDateTime('2021-09-01T09:05:12+08:00');