Delphi datetime, date, time tdatetimepicker
Datetimedatetimedatetimepicker
1. The datetime, date, and time storage methods are essentially double. The integer part represents the date, and the decimal part represents the time. For more information, see the "date/time" Storage Method in access"
Tdatetimepicker has the preceding three attributes.
2. Set the kind attribute of tdatetimepicker to dtkdate to display the date, and set the second kind to dtktime to display the time, but not at the same time.
3. Use datetimepicker. Date and time to get the value. Note: Use trunc to get the value of date and use frac to get the value of time.
4. date, time, and datetime of datetimepicker are equal.
The following is an example:
Add a tdatetimepicker, two tedit, and two buttons to a new project, and set the Event code for the two buttons as follows:
{Datetimepicker1: 13:00:00}
Procedure tform1.button1click (Sender: tobject); // extract the date part and determine its value
VaR
T: tdatetime;
Begin
T: = datetimepicker1.date;
Edit1.text: = datetimetostr (t );
End;
Procedure tform1.button2click (Sender: tobject); // you can determine whether date and datetime are equal.
Begin
If datetimepicker1.time = datetimepicker1.datetime then
Begin
Edit2.text: = 'Equality'
End
Else
Begin
Edit2.text: = 'unequal ';
End;
End;
We can see that although only date or time is taken in our code, their values and datetime values are equal.
So if you use the following code
{Datetimepicker1: 13:00:00}
Procedure tform1.button1click (Sender: tobject); // extract the date part and determine its value
VaR
T: tdatetime;
Begin
T: = datetimepicker1.date + datetimepicker1.time;
// T: = trunc (datetimepicker1.date) + frac (datetimepicker1.time); // This is the date and time of datetimepicker1.
Edit1.text: = datetimetostr (t );
End;
Result: 2120-6-21 2:00:00
This is equivalent to multiplying the time and date of datetimepicker1 by 2. It does not mean that the date + time of datetimerpicker is equal to datetime.
However, if you use trunc to take the integer part and add frac to take the fractional part, the sum obtained by the two will be equal to the original sum.
Refer:
Http://ifso.iteye.com/blog/1752420