Requirement: return the time difference between the time on the master computer expressed in minutes and the Global Standard Time (UTC). For example, the time difference between 09:07:54 and UTC should be 1263085674.
Call method:
Gettimezoneoffset (strtodatetime ('2017-01-10 09:07:54 '));
ImplementationCode:
// Function: Obtain the local time zone
Function gettimezone: integer;
VaR
M_timezone: time_zone_information;
I: integer;
Dtimezone: Double;
Itimezone: integer;
Begin
Gettimezoneinformation (m_timezone );
I: = m_timezone.bias;
Dtimezone: =-1*(I/60 );
Itimezone: = trunc (dtimezone );
Result: = itimezone;
End;
// Function: return the time difference between the time on the master computer in minutes and the Global Standard Time (UTC,
Function gettimezoneoffset (adatetime: tdatetime): extended;
VaR
X, Y: extended;
Iyear, Imonth, iday: word;
Ihour, Imin, ISEC, imsec: word;
Itimezone: integer;
Begin
Itimezone: = gettimezone;
Decodedatetime (adatetime, iyear, Imonth, iday, ihour, Imin, ISEC, imsec );
X: = (encodedate (iyear, Imonth, iday)-encodedate (, 1) * 86400;
Y: = ihour * 3600 + Imin * 60 + ISEC;
X: = x + y-(itimezone * 3600 );
Result: = X;
End;
// Function: Convert the UTC time value to the current system time
Function utctime2string (uitime: Cardinal): string;
VaR
Sdatetime: tdatetime;
Itimezone: integer;
Begin
Itimezone: = gettimezone;
Sdatetime: = encodedate (1970,1, 1) + (uitime + itimezone * 3600)/86400 );
Result: = formatdatetime ('yyyy-mm-dd hh: mm: ss', sdatetime );
End;
Requirement: return the time difference between the time on the master computer expressed in minutes and the Global Standard Time (UTC). For example, the time difference between 09:07:54 and UTC should be 1263085674.
Call method:
Gettimezoneoffset (strtodatetime ('2017-01-10 09:07:54 '));
Implementation Code:
// Function: Obtain the local time zone
Function gettimezone: integer;
VaR
M_timezone: time_zone_information;
I: integer;
Dtimezone: Double;
Itimezone: integer;
Begin
Gettimezoneinformation (m_timezone );
I: = m_timezone.bias;
Dtimezone: =-1*(I/60 );
Itimezone: = trunc (dtimezone );
Result: = itimezone;
End;
// Function: return the time difference between the time on the master computer in minutes and the Global Standard Time (UTC,
Function gettimezoneoffset (adatetime: tdatetime): extended;
VaR
X, Y: extended;
Iyear, Imonth, iday: word;
Ihour, Imin, ISEC, imsec: word;
Itimezone: integer;
Begin
Itimezone: = gettimezone;
Decodedatetime (adatetime, iyear, Imonth, iday, ihour, Imin, ISEC, imsec );
X: = (encodedate (iyear, Imonth, iday)-encodedate (, 1) * 86400;
Y: = ihour * 3600 + Imin * 60 + ISEC;
X: = x + y-(itimezone * 3600 );
Result: = X;
End;
// Function: Convert the UTC time value to the current system time
Function utctime2string (uitime: Cardinal): string;
VaR
Sdatetime: tdatetime;
Itimezone: integer;
Begin
Itimezone: = gettimezone;
Sdatetime: = encodedate (1970,1, 1) + (uitime + itimezone * 3600)/86400 );
Result: = formatdatetime ('yyyy-mm-dd hh: mm: ss', sdatetime );
End;