Time Operation Technology in Delphi (2)

zhaozj2021-02-16  46

Conversion functions between various time types

DateTimetOfileDate function:

Definition: DateTimetOfileDate (datetime: tdatetime): integer;

Role: Transforming a TDATETIME type to the time in the DOS environment, the TDATETIME type of time in the DOS environment is different from the TDATETIME type in the VCL, in order to maintain the time consistency, you need to use the DateTimetOfileDate function. Conversion, the value of the returned Integer is the value for describing the time under DOS.

DateTimetosystemTime process:

Definition: Procedure DateTimetosystemTime (datetime: tdatetime; var systemtime: tsystemtime);

Role: Convert a TDATETIME type to the TSYSTemTime type used by the WIN API function, which is used when using the WinAPI function to manipulate time.

SystemTimetODateTime function:

Definition: Function SystemTimetodatetime (const systemtime): tdatetime; TDATETIME DITIME

Role: Convert a number of TSYSTEMTIME types obtained in the WinAPI function to the TDATETIME type.

DateTimeTotimeSTAMP function:

TimeStamptodateTime function:

Definition: DateTimeTotimeStamp (datetime: tdatetime): TTIMESTAMP;

Function TimeStamptodateTime (Const TimeStamp: TtimeStamp): TDATETIME;

Role: Used to perform mutual conversion between TDataTime types and TTIMestAmp. TDataTime is drawn with a Double, and TTIMestamp is separately described by two shaping numbers. Two types of differences can refer to the data type description section of the start of the article.

EncodeDate function:

Definition: Function EncodeDate (Year, Month, Day: Word): TDATETIME

Role: Enter the value of year, month (MONTH), day (day), return this date to the TDATETIME type, the range of 1-9999, the range of the month is 1-12, the scope of the date is the month The situation is determined, if the input value is out of range, an ECONVERTERROR error will be generated.

DecodeDate process:

Definition: Procedure DecodeDate (Date: Tdatetime; VAR Year, Month, Day: Word);

Role: Enter a date of TDATETIME type and turn it into a year (MONTH), day (day) value. If the input value is 0 or less than 0, the month is 0,

Encodetime function:

Definition: Encodetime (Hour, min, sec, msec: word): TDATETIME;

Role: Enter the value of hours, division (min), second (sec), microsecond (MSEC), returns a TDATETIME type, which is a decimal number between 0 and 1. The value of HOUR is 0-23, and the value of MIN is 0-59. The value of SEC ranges from 0-59. The value of the MSEC is 0-999. If the input value is out of the range, an ECONVERTERROR is generated. error. Decodetime process:

Definition: Procedure Decodetime (Time: TDATETIME; VAR HOUR, Min, Sec, Msec: Word);

Role: Enter a value of a time, convert it to hours, division (min), second (sec), microsecond (MSEC).

TDATETIME Type and String Conversion Function:

DateTimetostr function:

DateTostr function

Timetostr function

Definition: Function DateTimetostr (datetime: tdatetime): String;

Function Timetostr (Time: tdatetime): String;

Function Timetostr (Time: tdatetime): String;

Role: Conversion of a TDATETIME type into a string, DateTimetostr conversion date and time, DateTostr only conversion date, Timetostr only conversion time. The converted output is YYYY-M-D h: M: S

STRTODATETIME function

STRTODATE function

STRTOTIME function

Definition: Function StrtodateTime (const s: string): TDATETIME;

Function Strtodate (const s: string): TDATETIME;

Function Strtotime (const S: string): tdatetime;

Role: Transform strings with date time format to TDATETIME, where s must be a valid string, such as

YY-MM-DD HH: MM: SS format, otherwise the EconvertError event will be triggered, and the error message is prompted.

The string of the time portion must be composed of 2 to 3 numeric strings, and divide the separated characters set in the Windows area setting, the format requires the settings in the Windows area setting, where HH, MM (Hours, minutes) must be added, SS (second) can be selected, or the AM and PM are added to the afternoon, at this time, the system will consider using a 12-hour representation, otherwise it is considered to adopt a 24-hour representation.

The format of the date section requires the short-term format in the Windows area setting, and is also composed of 2 to 3 numeric strings. If there is only two numbers in the string, it is considered to be a month and date, and the current year is adopted. ,

If the two-year representation method is used in the zone setting, the system will handle the following method:

Current year

Start year

Reference value

Enter a year 03

Enter a year 50

Enter a year 68

1998

0

1900

1903

1950

1968

2002

0

2000

2003

2050

2068

1998

50

1948

2003

1950

1968

2000

50

1950

2003

1950

1968

2002

50

1952

2003

2050

1968

2020

50

1970

2003

2050

2068

2020

10

2010

2103

2050

2068

First, in the regional setting, the starting year of the two years. If the two years are set in the regional settings, the starting year is 32 years. If this start year is 0, it is considered two digits. The year is all in this century. If in fact, the current year is reduced to subtract the value of the starting year, this value is called the reference value, which is greater than or equal to this value, otherwise it is considered to be the next century, below Given several examples:

DateTimetostring process:

FormatorTime function:

Definition: Procedure DateTimetostring (Var Result: string; const format: string; datetime: tdatetime);

Function Formator (const format: string; datetime: tdatetime): String;

Role: By defining the format in the format string to get the time string, for example, "Today is May 5, 2002, Friday" can use these two methods, these two methods are the same, just one The output string is obtained by sharing variables. The value is in the result, one is to acquire the output string by the return value, and the DateTime parameter is a desired date value, and the Format is combined with the format flag to the additional string. Additional string "", like the Printf function in C. If "Today is May 5, 2002, Friday" Format is' "Today is" YYYY "year" MM "month" DD "day , "DDDD ', YYYY, MM, DD, DDDD are all formatted, and the interpretation of various format identities is as follows:

D: Show days with one or two integers (1-31)

DD: Show days with two integers, less than two bits (01-31)

DDD: Displays the current star number according to the thumbnail. If Windows is an English version, it is displayed as MON-Sun. If it is a Chinese version, it will be displayed with DDDD.

DDDD: Displays the current star number according to the full mode, such as Windows is an English version, display Monday-Sumday, if it is a Chinese version, show Monday ~ Sunday

DDDDD: Outputs in short date in the area settings.

DDDDDD: Outputs in the long-term format in the area settings.

M: Use one or two-digit integers (1-12)

MM: Use two integers to display the month, less than two digits (01-12)

MMM: Use a thumbnail display to display the month name, the English version is displayed as Jan-Dec, the Chinese version is mmmm

MMMM: Use the full way to display the month name, the English version is displayed as January-December, the Chinese version is January to December

YY: Press two-digit mode to display the year (00-99)

YYYY: Display year by four-digit integer (0000-9999)

H: Show an hour with one or two digits (0-23)

HH: Use two integers to display hours, less than two digits (00-23) N: Show minutes with one or two integers (0-60)

NN: Show the minute, less than two digits, 0 complements (00-60)

S: Use one or two digits to display the number of seconds (0-60)

SS: Show the number of seconds with two integers, less than two digits 0 to make up (00-60)

Z: Use one to two integers to display milliseconds (0-999)

ZZZ: Use three integers to display milliseconds, less than three use 0 complement (000-999)

TT: Display date according to the format in the area setting

AM / PM: Used for 12-hour display, with AM, represents from 0:00 to 12, PM represents from 12 o'clock to 0 points.

Variables related to time:

Delphi encapsulates the various information of the area and defines a series of variables, which describes the partial variables associated with time:

Dateseparator: char

Date separator for date on the date of date

TimeseParetor: char

Time separator for separation hours, minutes, seconds

ShortdateFormat: String

The definition of short date format in the area settings.

LongdateFormat: String

The definition of the regional settings of the long date format.

ShortTimeFormat: string

The definition of short-time format in the area settings.

LongtimeFormat: String

The definition of the regional settings of the long time format.

TimeamString: String

Used to express a string of the morning

TimePMString: String

Used to express a string of the afternoon

Shortmonthnames: array [1..12] of string;

For abbreviations represent the array of month names, the string of MMM identifies displayed when using formatdatetime

Longmonthnames: array [1..12] of string;

The array used to complete the month name is the string of the MMMM identifier displayed when using formatdatetime.

ShortdayNames: array [1..7] of string;

Used to thumbnail representations that represent the name of the week, is the string of DDD identifies displayed when using formatdatetime

LongdayNames: array [1..7] of string;

An array used to completely represent the name of the week is the string of DDD identifies displayed when using formatdatetime.

TwodigityEarcenturyWindow: Word = 50;

At the beginning of the two years.

Ok, Delphi is basically finished, and some new operation functions are provided in Delphi6, but it is relatively simple. I believe that everyone can understand, so on some operation skills for time, I believe it After you have finished this article, you can have some, here is not described in detail, the same function should have a variety of implementation methods. This article mainly refers to the online help of Delphi5, this article introduces most of the functions in the online help, here is not one listed, refer to online help, I hope this article can improve your operating time technology. It also provides some convenience when you read the online help. Currently I am engage in the website of the Delphi function, interested friends can visit http://www.togetherdev.com

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

New Post(0)