If you want to convert a dateTime stored in UTC time to Local Time and vice versa you can use this 2 functions
function
UTCToLocalTime(AValue: TDateTime): TDateTime;
function
LocalTimeToUTC(AValue: TDateTime): TDateTime;
function
UTCToLocalTime(AValue: TDateTime): TDateTime;
var
SysTime1,
SysTime
2: TSystemTime;
TZinfo: TTimeZoneInformation;
begin
GetTimeZoneInformation(
TZinfo
);
DateTimeToSystemTime(AValue,
SysTime
1);
SystemTimeToTzSpecificLocalTime(@
TZinfo
,
SysTime
1,
SysTime
2);
Result := SystemTimeToDateTime(
SysTime
2);
end
;
function
LocalTimeToUTC(AValue: TDateTime): TDateTime;
var
SysTime
1,
SysTime
2: TSystemTime;
TZinfo
: TTimeZoneInformation;
begin
GetTimeZoneInformation(
TZinfo
);
TZinfo
.
Bias := -
TZinfo
.
Bias;
TZinfo
.
StandardBias := -
TZinfo
.
StandardBias;
TZinfo
.
DaylightBias := -
TZinfo
.
DaylightBias;
DateTimeToSystemTime(AValue,
SysTime
1);
SystemTimeToTzSpecificLocalTime(@
TZinfo
,
SysTime
1,
SysTime
2);
Result := SystemTimeToDateTime(
SysTime
2);
end
;
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου