Algorithm Math Delphi

Title: How to convert server time to local time?
Question: Many time we are faced with the situation when we have to show data received from a central server in different countries. The problem is all datetime at server are according server location, however the client application should see all datetime translated for local time zone.
Answer:
To show data according to current user time-zone, the application need to get the time bias information using following API.
function GetLocalTimeBias:Integer
var
timeBias:_TIME_ZONE_INFORMATION;
begin
GetTimeZoneInformation(timeBias);
Result := -1 * (timeBias.Bias + timeBias.DaylightBias+gIntMyServerTimeBias);
end
The above function uses GetTimeZoneInformation to get the Time bias information for the local machine. You must add your server timebias information to the timeBias.Bias field. The field value is in minutes and hence all values should be in minutes. The structure _TIME_ZONE_INFORMATION is defined as:
_TIME_ZONE_INFORMATION = record
Bias: Longint;
StandardName: array[0..31] of WCHAR;
StandardDate: TSystemTime;
StandardBias: Longint;
DaylightName: array[0..31] of WCHAR;
DaylightDate: TSystemTime;
DaylightBias: Longint;
end;
You should also note that the timebias information is according to UTC or GMT time. Hence if you are in india (GMT +5:30) the GetTimeZoneInformatin function returns -330 as time bias. Please note the -,+ signs. If your server is running on GMT+ time then the value should be -ive, however if your server is running on GMT- time, then the value should be +ive.
Okay, next step, after getting this value, you must redesign your SQL queries (if you use database to store data received from the server) to use timebias information. For example:
myNewSQL :=format('SELECT fielda, fieldb, dateAdd("n",%d,sent_on) as datefield from mytable;',[GetLocalTimeBias()]);
The above select statement uses dataAdd function for converting remote time data to local time data.
Hope this will help you all who are looking for localization of remote server data.