Time and correlation type (1)-tdatetime and double

Source: Internet
Author: User
// Related functions: sysutils. floattodatetime (); sysutils. tryfloattodatetime ();

  

In the system unit definition, tdatetime = type double;

Tdatetime is an 8-byte 64-bit data, but a double alias.

 
{Test: tdatetime is a double} var T: tdatetime; D: Double; s: string; begin T: = encodedatetime (2009, 5, 22, 11, 22, 33,999 ); {forced conversion} D: = double (t); showmessage (floattostr (d); // 39955.4740046181 {implicit conversion} D: = T; showmessage (floattostr (d )); // 39955.4740046181 {do not need to convert} showmessage (floattostr (t); // 39955.4740046181 {treat a double as tdatetime} s: = formatdatetime ('yyyy-m-d h: m: S: Z', 39955.4740046181); showmessage (s); // 2009-5-22 11: 22: 33: 999end;

  

No double will be converted into a valid time. The sysutils unit returns the minimum and maximum time constants:

Const mindatetime: tdatetime =-657434.0; {01/01/0100 12:00:00. 000 am} maxdatetime: tdatetime = 2958465.99999; {12/31/9999 11:59:59. 999 pm}

To be safe, use floattodatetime (); or tryfloattodatetime (); to convert a number to tdatetime;
There is no need to use a function for reverse conversion.

 
{Use tryfloattodatetime} var T: tdatetime; D: Double; begin D: = 0; If tryfloattodatetime (D, T) Then showmessage (datetimetostr (t); // 1899-12-30end; {floattodatetime is used; If the conversion fails or encounters an invalid time, an exception is thrown.} var T: tdatetime; D: Double; begin D: = 0; T: = floattodatetime (d ); showmessage (datetimetostr (t); // 1899-12-30end; {when the time is 00:00:00, January 1, December 30, 1899, the time value of tdatetime is 0} var D: Double; T: tdatetime; begin T: = strtodatetime ('2017-12-30 0: 0: 0: 0'); D: = double (t); showmessage (floattostr (d )); // 0end;

  
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.