Delphi gets the current time and date of the system and the format time

Source: Internet
Author: User
Tags current time datetime time and date
Get system Current time in this example, the FormatDateTime function is used primarily to format datetime as the specified string. This function can be used to output many forms of time format.

The results of the program run are shown in Figure 6.1

The main code is as follows:
Procedure Tform1.button1click (Sender:tobject);
Begin
Label1.Caption: = FormatDateTime (' Hh:nn:ss ', now ());
End

Get System Current Date

When the user clicks a button in the form, the program uses the DATETIMETOSTR function to convert the current date to a string that is displayed on the label.

The results of the program run are shown in Figure 6.2.


Figure 6.2 Getting the current date of the system

The main code is as follows:
Procedure Tform1.button1click (Sender:tobject);
Begin
Label1.Caption: = Datetimetostr (Date ());
End

Format datetime as specified

     This example formats the DateTime as the specified format the FormatDateTime function is applied primarily. Use this function to format the current date time as a custom format. The

     program runs the result as shown in Figure 6.3.

Figure 6.3   Format the datetime as the specified format

     The main code is as follows:
     Procedure Tform1.timer1timer (Sender:tobject);
    begin
     label1.caption: = Datetimetostr (now ());
    end;
    procedure Tform1.button1click (sender:tobject);
    begin
     label2.caption: = FormatDateTime (' yyyy mm month DD Day HH when nn sub ss seconds ', now ());
    end;

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.