Time Operation Technology in Delphi (1)

zhaozj2021-02-16  47

When writing an application, we need to deal with time and date, therefore often require some control technology for time, in Delphi, provide a set of operation functions for the date and time, where I will introduce it in detail Time operation technology in Delphi, I hope to help everyone.

Delphi used to indicate time type:

First, take a look at several data structures used to describe time in Delphi, the operation of time is actually the operation of these structures.

TDATETIME Type:

The most commonly used data type TDATETIME type of Delphi is the same, like a normal shaping, you can define a date-type variable to the date to operate in the program. The TDATETIME type is substantially a double-type number, which is the TDATETIME type in Delphi. Decrease and subtraction in the sky, such as numbers 1, January 1, 1900, Digital-1 represents December 29, 1989. And the fractional part is used to indicate time, its value is the ratio of the time to represent the total time of the day, as 6/24 = 0.25 in the morning, and 6:15 in the morning (6 * 60 15) / (24 * 60) = 0.26041666666666666666666666667, below, give a few examples show the interaction between TDATETIME type and Double type

0 12/30/1899 00:00:00

2.75 1/1/1900 18:00:00

-1.25 12/29/1899 6:00:00

35065 1/1/1996 00:00:00

I believe that everyone must understand the conversion method between TDATETIME and DOUBLE, so it is fundamentally the same as the TDATETIME is exactly the same.

TTIMESTAMP Type:

This is a structural type used to describe the date and time, which is defined in Delphi:

Type

TTIMESTAMP = Record

Time: Integer; {starting from midnight to milliseconds of the specified time}

Date: integer; {Based on this day to the number of days of pointing date}

END;

Compared to TDATETIME, it can more intuitively represent high precision time, generally used for milliseconds, and used to represent longer.

PsystemTIME Type:

A pointer type structure for time operation in WinAPI. His definition is:

Type

Psystemtime = ^ Tsystemtime;

TsystemTime = Record

Wyear: word;

WMONTH: WORD;

WDAYOFWEEK: WORD;

WDAY: WORD;

WHOR: WORD;

WMINUTE: WORD;

WSECond: Word;

WMilliseconds: Word;

END;

This structure is used to use when calling WinAPI operations.

After understanding the essence of various time types, I believe that everyone has a set of time for these types of time, but it also provides a complete set of process functions for operation time, which is defined in sysunit. In the unit, you will now introduce you to the related functions in Delphi:

Function for time operation

Date function:

Definition: date: tdatetime;

Role: Return to the current date

Example: currentdate: = date; dayofweek function:

Definition: Function Dayofweek (date: tdatetime): integer;

Role: Get the value value of the specified date, return 1 ~ 7, representing Sunday to Saturday.

IncuntH function:

Definition: Function Incmonth (const date: tdatetime; tdatetime): TDATETIME

Role: Seeking a given date Data after NumberofmontHs date later.

Example: Date1: = Incmonth (Date, 10);

If today is 2002-5-3, Date1 is 2003-3-3

IsleApyear function:

Definition: Function isleApyear (Year: Word): Boolean

Role: Is it judged whether the designated year is a leap year;

Example: if IsleApyear (2000) Then ShowMessage ('This year is a leap year');

NOW function:

Definition: function now: tdatetime;

Role: Used to get the current date time

Example: CurrentDateTime: = now

ReplaceDate process

Definition: Procedure ReplaceDate (var DateTime: tdatetime; const newdate: tdatetime);

Role: Use the parameter NewDate date to replace the date part of the parameter datetime, but does not change the time portion.

ReplaceDate process

Definition: Procedure Replacestime (var datetime: tdatetime; const newtime: tdatetime);

Role: Use the parameter newdate time to replace the time portion of the parameter DateTime, but does not change the date part.

If the above two processes are used together, it is equivalent to assignment.

Time function:

Definition: function time: tdatetime;

Role: Returns the current time

Example: CURRENTTIME: = TIME;

It is possible to improve your operational time technology and provide some convenience when you read online help.

转载请注明原文地址:https://www.9cbs.com/read-25754.html

New Post(0)