How to convert a historical timestamp to a different time zone from DST to Delphi?

I need to convert a historical timestamp from GMT to BST in Delphi (Win32). I can not use the current regional settings in the OS to perform the conversion, because it will not have the corresponding Daylight Saving Time (DST) for the historical time.

Can I use the VCL API or Win32 API?

+5
source share
1 answer

Delphi TZDB may be useful. The main feature is the class that processes time using the tz database , which, if it contains enough historical data, will allow you to use UTC as an intermediary. The tz database aims to have rules for all time zones around the world and various time shifts for things like leap years, daylight saving time, calendar changes, etc., since they have been around UTC since the Unix era (Midnight , Jan 1, 1970).

After installing the package, the use will be performed on the lines of the following form:

function ConvertFromGMTToBST(const AGMTTime: TDateTime): TDateTime;
var
   tzGMT, tzBST: TTimeZone;
   UTCTime: TDateTime;
begin
    tzGMT := TBundledTimeZone.GetTimeZone('GMT');
    tzBST := TBundledTimeZone.GetTimeZone('BST');
    UTCTime := tzGMT.ToUniversalTime(AGMTTime);
    Result := tzBST.ToLocalTime(UTCTime);
end;

. , GMT BST tz. , . (, America/New_York). -, , Delphi XE+. TZDB , Delphi 6 ( FreePascal), .

, , 20- .

+12

All Articles