Delphi development takes system time and time format

Take the current system time
nowstr :=FormatDateTime('yyyy/mm/dd hh:mm:s', Now());
take the time difference
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ;
procedure TForm1.FormCreate(Sender: TObject);
var
t1,t2: TDateTime;
b: Boolean;
begin
t1 := StrToDateTime('2009-5-20 11:22:33');
t2 := StrToDateTime('2009- 5-21 11:22:33');

{Is the two time difference within 24 years?}
b := WithinPastYears(t1, t2, 24); //True

{Is the two time difference within 24 months?}
b := WithinPastMonths(t1, t2, 24); //True

{Is the two time difference within 24 weeks?}
b := WithinPastWeeks(t1, t2, 24); //True

{Is the two time difference within 24 days?}
b := WithinPastDays(t1, t2, 24); //True

{Is the two time difference within 24 hours?}
b := WithinPastHours(t1, t2, 24); //True

{Is the two time difference within 24 minutes?}
b := WithinPastMinutes(t1, t2, 24); //False

{Is the two time difference within 24 seconds?}
b := WithinPastSeconds(t1, t2, 24); //False

{Is the two time difference within 24 milliseconds}
b := WithinPastMilliSeconds(t1, t2, 24); //False

// ShowMessage(BoolToStr(b, True));
end;

end.

DateUtils time unit, very useful.

Remember to quote this unit, otherwise it cannot be used.

CompareDate Compare the size of the date part of
two date and time values ​​CompareDateTime Compare the size of the two date and time values
CompareTime Compare the size of the time part of two date and time values
DateOf Remove the time part of the
date and time value DateTimeToJulianDate Convert the date and time value to Julian Date
DateTimeToModifiedJulianDate conversion The date and time value is an improved Julian day
DateTimeToUnix Converts the date and time value to the Unix/Linus date and time value
Day of week The constant
DayOf returns the day of the day of the week in the ISO 8601 standard
DayOfTheMonth returns a date and time value Days
DayOfTheWeek returns a date and time value is the day of the week
DayOfTheYear returns a date and time value is the day of the year
DaysBetween returns the integer number of days between two date and time values
DaysInAMonth returns the number of days in the specified year and month
DaysInAYear returns Specifies the number of days in the year
DaysInMonth returns the number of days in the month of
a date-time value
DaysInYear returns the number of days
in the year of a date-time value DaySpan returns the number of decimal days of the difference between two date-time values DecodeDateDay returns the year sum of a date-time value The day of the year
DecodeDateMonthWeek returns the year, month, week of that month, and day of the week of
a date and time value DecodeDateTime returns the year, month, day, hour, minute, second, and millisecond of
a date and time value DecodeDateWeek returns a date and time value The year, the week of the year, and the day of the week.
DecodeDayOfWeekInMonth returns the year, month, day of the week, and day of the month of a date-time value.
EncodeDateDay returns the number of the specified year and year The date and time value of the
day EncodeDateMonthWeek returns the date and time value of the specified year, month, week of the
month, and day of the week. EncodeDateTime returns the date and time value of the specified year, month, day, hour, minute, second, and millisecond
EncodeDateWeek returns the date and time value of the
specified year, week of the year, and day of the week EncodeDayOfWeekInMonth returns the date and time value of the specified year, month, and day of the month
EndOfADay returns the specified year, the number of the year The date and time value of the last second of the day
EndOfAMonth Returns the date and time value of the last second of the last day of the specified year and month EndOfAWeek Returns the date and time value of the last second of the
specified year, week of that year, and day of that week
EndOfAYear Return the date and time value of the last second of the last day of the specified year
EndOfTheDay Return the date and time value of the last second of the day of the specified date and time value EndOfTheMonth Return the date and time value of the last second
of the month of the specified date and time value EndOfTheDay
EndOfTheWeek returns the date and time value of the last second of the last day of the week for the specified date and time value EndOfTheYear returns the date and time value of the last second of the last day
of the year for the
specified date and time value
HourOf returns the hour part of the specified date and time value HourOfTheDay Returns the specified date and time value The hour part of the date and time value.
HourOfTheMonth returns the number of hours that have elapsed from 0:00 on the first day of the month of the specified date and time value to the hour of the specified date . HourOfTheWeek returns from 0:00 on the first day
of the week in the specified date and time value The number of hours that have elapsed in the hour of the
specified date HourOfTheYear Returns the number of hours that have elapsed from 0:00 on the first day of the year in the specified date and time value to the hour on the specified date
HoursBetween Returns the difference between two specified date and time values
HourSpan returns the number of hours (including the decimal part) between two specified date and time values.
IncDay returns the value of the date and time value moved backward by the specified number of days.
IncHour returns the value of the date and time value moved backward by the specified number of hours.
IncMilliSecond returns The date and time value moves backward by the specified number of milliseconds.
IncMinute returns the date and time value moves backward by the specified number of minutes.
IncSecond returns the date and time value moves backward by the specified number of seconds.
IncWeek returns the date and time value moves backward by the specified number of weeks.
IncYear returns the value of the date and time value that moves backward by the specified number of weeks
IsInLeapYear Determines whether the year of the
specified date and time value is a leap year IsPM Determines whether the time of the specified date and time value is after 12:0:0 noon
IsSameDay Determines whether a date and time value is the same day as a standard date and time value
IsToday Determines whether a date and time value is the same day
IsValidDate Determines whether the specified year, month, and day are valid dates
IsValidDateDay Determines whether the specified year and the number of days in the year are valid The number of valid days in the year
IsValidDateMonthWeek Determines whether the specified year, month, week of the
month, and day of the week are valid dates IsValidDateTime Determines whether the specified year, month, day, hour, minute, second, and millisecond are valid Valid date and time value
IsValidDateWeek Determines whether the specified year, week of the year, and day of the week are valid dates
IsValidTime Determines whether the specified hours, minutes, seconds, and milliseconds are valid times.
JulianDateToDateTime converts Julian dates to The date and time value
MilliSecondOf returns the millisecond part of the
specified date and time value MilliSecondOfTheDay returns the number of milliseconds from the beginning of the specified date and time value to the specified time at 0: 0: 0 seconds on the day of the
specified date and time value MilliSecondOfTheHour returns the hour, 0 minutes and 0 seconds of the specified date and time value
MilliSecondOfTheMinute returns the number of milliseconds from 0 milliseconds to its specified time MilliSecondOfTheMinute returns the number of milliseconds from 0 milliseconds to its specified time of the
specified date and time value MilliSecondOfTheMonth returns the number of milliseconds from the month 1 of the specified date and time value to the month 1 day, minute, 0 second, and 0 millisecond to the specified date and time value The milliseconds of the specified time
MilliSecondOfTheSecond returns the millisecond part of the specified date and time value
MilliSecondOfTheWeek returns the number of milliseconds from 0: 0: 0 seconds 0 milliseconds to the specified time on Monday of the week of the
specified date and time value MilliSecondOfTheYear returns the number of milliseconds from 0: 0: 0: 0 seconds 0 milliseconds to the specified time of the year of the specified date and time value Milliseconds of the time
MilliSecondsBetween returns the number of milliseconds between two specified date and time values ​​(integer)
MilliSecondSpan returns the number of milliseconds between two specified date and time values ​​(decimal)
MinuteOf returns the minute part of the specified date and time value
MinuteOfTheDay returns the specified date The number of minutes from
0:00 on the day of the time value to the specified time MinuteOfTheHour returns the minute part of the
specified date and time value MinuteOfTheMonth returns the number of minutes from 0:00 on the 1st of the month of the specified date and time value to its specified time
MinuteOfTheWeek returns The number of minutes from
0:00 on the first day of the week of the specified date and time value to the specified time MinuteOfTheYear Returns the number of minutes from 0:00 on January 1 of the year of the specified date and time value to the specified time
MinutesBetween returns two The number of minutes between the specified date and time values ​​(integer)
MinuteSpan returns the number of minutes between the two specified date and time values ​​(including decimals)
ModifiedJulianDateToDateTime converts the corrected Julian date to the date and time value
MonthOf returns the number of the specified date and time value Month Part
MonthOfTheYear returns the month part of the specified date and time value
MonthsBetween returns the month (integer) that is the difference between two specified date and time values.
MonthSpan returns the month that is the difference between two specified date and time values ​​(including decimals).
NthDayOfWeek returns the day of the week of the specified date and time value.
OneHour constant Delphi The constant
OneMillisecond that is inversely proportional to time The constant Delphi The constant that is inversely proportional to time
OneMinute The constant Delphi The constant that is inversely proportional to time
OneSecond The constant Delphi The constant that is inversely proportional to time
RecodeDate Replaces the date part of the
specified date and time value
RecodeDateTime Choose to replace the specified date and time value RecodeDay Replace the day part of the
specified date and time value
RecodeHour Replace the hour part of the specified date and time value
RecodeMilliSecond Replace the millisecond part of the specified date and time value
RecodeMinute Replace the minute part of the specified date and time value
RecodeMonth Replace the month part of the specified date and time value RecodeSecond Replace the specified date and time value The second part of
RecodeTime replaces the time part of the
specified date and time value RecodeYear replaces the year part of the specified date and time value
SameDate Determines whether the year, month, and day parts of
two date and time values are the same SameDateTime Determines the year, month, and day of two date and time values , Hours, minutes, seconds, milliseconds are the same
SameTime Determines whether the hour, minute, second, and millisecond parts of two date and time values ​​are the same.
SecondOf returns the second part of the specified date and time value.
SecondOfTheDay returns the number of seconds from the specified date and time value of 0: 0: 0 to its specified time.
SecondOfTheHour returns The number of seconds
from the hour 0 minute 0 second of the specified date and time value to the specified time SecondOfTheMinute Returns the number of seconds from the minute 0 seconds of the specified date and time value to the specified time
SecondOfTheMonth Returns the number of seconds from the specified date and time value on the 1st of the month at 0:00 0
SecondOfTheWeek returns the number of seconds from 0:00:00:00 on Monday of the week of the specified date and time value to its specified time
SecondOfTheYear returns the number of seconds from the specified date and time value to January 1st of the year 0 The number of seconds from hour 0 minute 0 second to its specified time
SecondsBetween returns the number of seconds between two specified date and time values ​​(integer)
SecondSpan returns the number of seconds between two specified date and time values ​​(including decimals)
StartOfADay returns the specified The date and time value of the beginning of the day (0: 0: 0: 0, 0, 0, and 0 milliseconds)
StartOfAMonth returns the date and time value of the first day of the specified year and month (0: 0: 0: 0: 0: 0 ms)
StartOfAWeek returns the specified year, week,
StartOfAYear returns the date and time value of the beginning of the specified year (January 1st, 0:0 minute, 0 second and 0 milliseconds)
StartOfTheDay returns the date and time value of the specified date and time starting on that day ( 0 hour 0 minute 0 second 0 millisecond) date and time value
StartOfTheMonth returns the date and time value of the beginning of the month (1st, 0: 0: 0, 0, 0, and 0 milliseconds) of the
specified date and time value . StartOfTheWeek returns the date and time of the week that the specified date and time value begins (the first day 0: 0: 0: 0 seconds and 0 milliseconds) The value
StartOfTheYear returns the date and time value of the beginning of the year (January 1st, 0: 0: 0: 0, 0, and 0 milliseconds) of the
specified date and time value. TimeOf returns the time part of the specified date and time value
Today returns the current day's date
Tomorrow returns the next day's date
TryEncodeDateDay calculation The date and time value
of the specified year and day of the year TryEncodeDateMonthWeek Calculate the date and time value of the specified year, month, week of the
month, and day of the week TryEncodeDateTime Convert the specified year, month, day, hour, minute, second, millisecond For the date and time value
TryEncodeDateWeek conversion, specify the year, the week, and the day of the week as the date and time value
TryEncodeDayOfWeekInMonth convert the specified year, month, and the week of the month as the date and time value
TryJulianDateToDateTime conversion specify the Julian day as the date and time The value
TryModifiedJulianDateToDateTime converts the specified modified Julian day to the date and time value
TryRecodeDateTime Selects to replace some parts of the specified date and time value
UnixToDateTime converts the Unix or Linux date and time value to the Delphi date and time value
WeekOf Returns the specified date and time value is the week of the year
WeekOfTheMonth returns the week of the specified date and time value of the month
WeekOfTheYear returns the week of the specified date and time value of the year
WeeksBetween returns the number of weeks between two specified date and time values ​​(integer)
WeeksInAYear returns the number of weeks in the specified year
WeeksInYear returns the number of weeks in the year of the
specified date and time value WeekSpan returns the number of weeks (including decimals) between the two specified date and time values
WithinPastDays Determines whether the difference between two dates is within the range of the specified number of days
WithinPastHours Determines two date and time Whether the difference between the values ​​is within the range of specified hours.
WithinPastMilliSeconds Determines whether the difference between the two date and time values ​​is within the range of specified milliseconds.
WithinPastMinutes Determines whether the difference between the two date and time values ​​is within the range of specified minutes.
WithinPastMonths determines the two dates. Whether the difference between the time values ​​is within the range of the specified month.
WithinPastSeconds Determines whether the difference between the two date and time values ​​is within the range of the specified number of seconds.
WithinPastWeeks Determines whether the difference between the two date and time values ​​is within the range of the specified number of weeks.
WithinPastYears Judgment Whether the difference between two date and time values ​​is within the range of the specified number of years.
YearOf returns the year part of the
specified date and time value.
YearsBetween returns the number of years (integer) that is the difference between two specified date and time values. YearSpan returns the value of the two specified date and time values. The number of years between (including decimals)
Yesterday returns the date one day before the current date (yesterday)

Guess you like

Origin blog.csdn.net/caoguanghui0804/article/details/108765593