How can I enable the datetimepicker control to display both dates and times, and modify and save them?

Source: Internet
Author: User

How can I enable the datetimepicker control to display both dates and times, and modify and save them?

My solution:
First, set the format attribute of the control to mm DD, yyyy, mm, mm, SS, and kind to dtktime.
Where you want to save the value in the control, such as in the change event (of course this is not a good place, it is enough to take only one time, this is just for you to view the effect), write the followingCode:
Procedure tfrom_sms.datetimepicker2change (Sender: tobject );
VaR
SS: string;
PP: pchar;
Begin
// Time1: = formatdatetime ('Mm minute SS second At HH on mm dd, yyyy ', datetimepicker2.datetime );
// The datetime attribute of the control cannot be used, because it only records changes in the part specified by the kind attribute (dtkdate or dtktime), but does not record changes in the other part.
PP: = stralloc (20); // allocate memory for pchar
Datetimepicker2.gettextbuf (PP, 20 );
SS: = pp;
Showmessage (SS );
Strdispose (PP); // For pchar to release memory, which must be available; otherwise, an error is returned.
End;

Note that the current bug is:
If the date is modified first, the date is automatically restored when the time is modified.
Therefore, you can only modify the time before modifying the date.

I wonder if you can solve this problem.

 

the reason why you don't need the maskedit (or simply edit) control is to use some advantages of datetimepicker:
1. valid input verification (year, month, day, hour, minute, and second have boundaries, and also involve issues such as leap year and month)
2. up and down arrow. you can try it. Although it is usually time-specific, it also has an effect on the date part in the example I changed. of course, this is secondary and dispensable. it is mainly about 1st points.

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.