Time Difference Between tdatetime and UTC

Source: Internet
Author: User

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.