Delphi date function (Day, Mon, Year, Week) using the method described

Day at the beginning of the function
●  function DateOf (const the Avalue: TDateTime): TDateTime;

Description
Use DateOf TDateTime a function used to type into a variable
with only a TDateTime variable dates.
For example:
ShowMessage (DateTimetostr (dateof (now ())));
you get is 2003/03/19
and showmessage (DateTimetostr ((now () )));
get is 2003/03/19 10:50:49

●function DateTimeToStr(DateTime: TDateTime): string;

Description
DateTimeToString function converts a TDateTime DateTime parameter into a
string, the use of global variables ShortDateFormat given format, the time portion in accordance with
a given format LongTimeFormat global variable.
Wherein the section is zero DateTime not be displayed.

For example:
ShortDateFormat: = 'YYYY dd mm';
ShowMessage (DateTimetostr ((now ())));
You will receive: 20030319 10:50:49


●procedure DateTimeToString(var Result: string; const Format: string; DateTime: TDateTime);

description: 

Methods DateTimeToString a TDateTime DateTime parameters provided by the format parameter Format
is converted into a string, and stored in Result.
For the format type Format, see Date-Time format strings help.

For example:
DateTimeToString (result, 'YYYY dd mm', now ());
then the result is the result: 20030319 10:50:49

●procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);

Description:
Sometimes in order to call the API function to use the system time, you can use DateTimeToSystemTime way to a
conversion time of a TDateTime variable into a TSystemTime type of system time.

●function DateTimeToUnix(const Avalue: TDateTime ): Int64;

Description:
Use DateTimeToUnix function to convert a TDateTime type variable time corresponding to a Unix format
date and time.
DATE-and-Time UNIX values are encoded seconds The AS that have have The Number of Elapsed
Operating since Midnight. 1 AT The Start of January, 1970.


●function DateToStr(Date: TDateTime): string;

Description:
Use DateToStr function portion can be obtained TDateTime date datetime type. Conversion format of the date depends on the
global variable ShortDateFormat.

●function DayOf(const Avalue: TDateTime): Word;

Description:
For a given date and time a TDateTime using DayOf function to get the date is the first day of the month.
The function returns a value between 1 and 31.
Note: The same result is obtained with the function DayOf DayOfTheMonth.

For example:
ShowMessage (IntToStr (dayof (now)));
get is: 19 (Today is the 19th of a month)

●function DayOfTheMonth(const Avalue: TDateTime): Word;

And DayOf same.

●function DayOfTheWeek(const Avalue: TDateTime): Word;

描述:
对于给定的TDateTime类型的日期时间,使用 DayOfTheWeek 函数能得到该日期是该星期的
第几天。DayOfTheWeek 函数的返回数值为 1 到 7,其中 1 表示星期一,而 7 表示星期日。
注意:DayOfTheWeek 是 ISO 8601 标准的(此标准为 星期一是一周的第一天)。对于一周
的第一天是星期日的标准,如果想获得星期数,请使用 DayOfWeek 函数。
Tip: To make the return value more readable, use the Day of week constants.

●function DayOfTheYear(const Avalue: TDateTime): Word;

描述:
根据给定的日期时间参数Avalue,使用 DayOfTheYear 函数能得到在该日期所在的年份中,该
日期按照顺序所计算的天数。因此,作为TDateTime类型的变量 “1月1日”在该函数所得到的
结果为 1 ,“1月2日”所得到的结果为 2,“2月1日”所得到的结果就为 32,依次类推。

●function DayOfWeek(Date: TDateTime): Integer;

Description

DayOfWeek returns the day of the week of the specified date as an integer between
1 and 7, where Sunday is the first day of the week and Saturday is the seventh.

Note: DayOfWeek is not compliant with the ISO 8601 standard, which defines Monday
as the first day of the week. For an ISO 8601 compliant version, use the DayOfTheWeek
function instead.

描述:
按照给定的TDateTime类型的参数Date,DayOfWeek 函数得到一周中的第几天,从1到7。
这里 星期日 是一周的第一天,而 星期六 是第七天。

●function DaysBetween(const ANow, AThen: TDateTime): Integer;

描述:
根据两个TDateTime类型的日期时间变量 ANow 和 AThen,DaysBetween函数能得到两者之间的
天数的差距。
DaysBetween 仅仅根据天数的不同来计算。因此,对于 1999年12月31日 下午11点59分 到
2000年1月1日 11点58分,该函数得到的结果是 0,因为两者之间的时间差别还差 1 分钟才到
1 天。

●function DaysInAMonth(const AYear, AMonth: Word): Word;

描述:
对于各定的 年份和月份,DaysInAMonth 函数能得到 该月份的总天数。
年份应该为 从 1 到 9999
月份应该为 从 1 到 12

●function DaysInAYear(const AYear: Word): Word;

描述:
对于给定的年份,DaysInAYear函数能得到该年份的总天数。
年份应该为 1 到 9999。

●function DaysInMonth(const Avalue: TDateTime): Word;

描述:
根据给定的TDateTime类型的时间日期参数Avalue,DaysInMonth函数能得到该月份的总天数。

●function DaysInYear(const Avalue: TDateTime): Word;

描述:
根据给定的TDateTime类型的时间日期参数Avalue,DaysInYear函数能得到该年份的总天数。

●function DaySpan(const ANow, AThen: TDateTime): Double;

描述:
根据两个TDateTime类型的日期时间参数ANow和AThen,DaySpan能得到在天数上的差距。
与 DaysBetween 函数不同,DaysBetween 函数 只是计算 整的天数,而 DaySpan函数会
将不足一天的数也得到。
注意:此函数返回的数值为 Double 型。

 

☆ Month 开头的函数

●function MonthOf(const Avalue: TDateTime): Word;

描述:
根据给定的TDateTime类型的时间日期参数Avalue,MonthOf函数能得到该年份的该月份数。
MonthOf返回数值为 1 到 12。
注意:MonthOf函数得到的数值与MonthOfTheYear函数相同

●function MonthOfTheYear(const Avalue: TDateTime): Word;

与MonthOf函数相同。

●function MonthsBetween(const ANow, AThen: TDateTime): Integer;

描述:
根据两个给定的TDateTime类型的参数ANow和AThen,MonthsBetween函数能得到两个日期在月份
上差距数。因为月份的天数是不同的,所以 MonthsBetween 函数返回的是一个近似值,该近似
值基于每个月份为 30.4375 天。不足一个月的数字将不被计算。
因此,例如,对于 2月1日 到 2月28日,MonthsBetween 返回的数值为 0。
同样,对于 2月1日 到 3月1日,MonthsBetween 返回的数值也是 0。

●function MonthSpan(const ANow, AThen: TDateTime): Double;

描述:
根据两个给定的TDateTime类型的参数ANow和AThen,MonthsBetween函数能得到两个日期在月份
上差距数。因为月份的天数是不同的,所以 MonthsBetween 函数返回的是一个近似值,该近似
值基于每个月份为 30.4375 天。与 MonthsBetween 函数不同,MonthsBetween函数不计算不足
一个月的数字,MonthSpan函数将会得到不足一个月的数字。
注意:此函数返回的类型为 Double

●function MonthStr(DateTime: TDateTime): string;

Description

HTTP message headers permit several formats for the representation of date and time
values. MonthStr converts a TDateTime value into a string representing the month.
MonthStr allows server applications to work with date values taken from HTTP request
messages, without worrying about the details of how they are formatted.

 

☆ Week 开头的函数

●function WeekOf(const Avalue: TDateTime): Word;

描述:
根据TDateTime类型的日期时间参数AValu,WeekOf函数会得到该星期为一年的第几个
星期。

●function WeeksInAYear(const AYear: Word): Word;

描述:
WeeksInAYear 函数根据年份得到在该年份中共包含多少个星期。

●function WeeksBetween(const ANow, AThen: TDateTime): Integer;

描述:
根据两个TDateTime类型的日期时间参数ANow和AThen,WeeksBetween函数将得到这两个时间在
星期上的差数。如果差数不足一个星期,则忽略掉。

●function WeekSpan(const ANow, AThen: TDateTime): Double;

描述:
根据两个TDateTime类型的日期时间参数ANow和AThen,WeeksBetween函数将得到这两个时间在
星期上的差数。如果差数不足一个星期,则WeekSpan函数不会忽略掉。
注意:此函数的返回类型为 Double

 

☆ Year 开头的函数

●function YearOf(const Avalue: TDateTime): Word;

描述:
根据给定的TDateTime类型的日期时间参数Avalue,YearOf函数能得到该日期的年份数字。
YearOf函数返回的数值为从 1 到 9999

●function YearsBetween(const ANow, AThen: TDateTime): Integer;

描述:
根据两个给定的TDateTime类型的参数ANow和AThen,YearsBetween函数能得到两个日期在年份
上差距数。因为年份的天数是不同的,所以 YearsBetween 函数返回的是一个近似值,该近似
值基于每年的天数为 365.25 天。不足的一年的差距将不会被计算。
因此例如:对于 1月1日和12月31日,如果这两个日期在同一年,则 YearsBetween 返回数值
为 0;如果这两个日期在临近的年份,则 YearsBetween 函数返回数值为 1。

●function YearSpan(const ANow, AThen: TDateTime): Double;

描述:
根据两个给定的TDateTime类型的参数ANow和AThen,YearsBetween函数能得到两个日期在年份
上差距数。因为年份的天数是不同的,所以 YearsBetween 函数返回的是一个近似值,该近似
值基于每年的天数为 365.25 天。与 YearsBetween 函数不同,YearsBetween函数将忽略掉不
足一年的数字,而 YearSpan 将计算不足一年的数字。
注意:该函数返回类型为Double


●function Yesterday: TDateTime;

描述:
Yesterday函数能得到当前日期的前一天的日期,返回数值中不包括时间部分。
例如:
当前日期是 2003/3/19
则 showmessage(datetimetostr(Yesterday));
将得到 2003/3/18

☆日期的合成
●function EncodeDate(Year, Month, Day: Word): TDateTime;

描述:
EncodeDate函数将根据参数 年份、月份、日子 而得到一个TDateTime类型的时间变量。

●function EncodeDateDay(const AYear, ADayOfYear: Word): TDateTime;

描述:
EncodeDateDay将根据参数年份和天数,而得到一个TDateTime类型的时间变量。
其中AYear 为 1 到 9999。
ADayOfYear 为日子在该年份顺序排列的天数,例如,1月1日时,ADayOfYear为1,
2月2日时,ADayOfYear为2,3月1日时,ADayOfYear为32。

●function EncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth: Word; const ADayOfWeek: Word =

1): TDateTime;

描述:
EncodeDateMonthWeek 函数将根据参数 年份、月份、星期数,星期几,来得到一个TDateTime类型
的时间变量。
其中AYear 为 1 到 9999。
其中AMonth 为 1 到 12。
AWeekOfMonth是在该月份的星期数,1 表示第一个星期,可能包含4天或更多的天数。
注意,一个月的第一天如果是 星期5,星期6或星期日,用表示这三天的AMonth数值必须设定
为上一个月份的数字,同时 AWeekOfMonth 要设为在上一个月所在的星期数。
同样,如果一个月的最后一天是 星期1,星期2,或星期3,那么用表示这三天的AMonth数值
必须设定为下一个月份的数字,同时 AWeekOfMonth 为 1。
ADayOfWeek表示星期几,星期一为1,星期二为2。

●function EncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond:

Word):TDateTime;

描述:
EncodeDateTime 根据参数 年份、月份、日子、小时、分、秒、毫秒 来得到一个TDateTime类型
日期时间。

●function EncodeDateWeek(const AYear, AWeekOfYear: Word; const ADayOfWeek: Word = 1): TDateTime;

描述:

EncodeDateWeek 根据参数 年份、星期数、星期几 来得到一个TDateTime类型日期时间。

AWeekOfYear是在该年份的星期数,1 表示第一个星期,可能包含4天或更多的天数。
注意,一年的第一天如果是 星期5,星期6或星期日,用表示这三天的AYear数值必须设定
为上一个年份的数字,同时 AWeekOfYear 要设为在上一个年所在的星期数。
同样,如果一年的最后一天是 星期1,星期2,或星期3,那么用表示这三天的AYear数值
必须设定为下一个年份的数字,同时 AWeekOfYear 为 1。
ADayOfWeek表示星期几,星期一为1,星期二为2。

●function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;

描述:
EncodeTime函数根据参数 小时、分、秒、毫秒 得到个一个TDateTime数值。

☆日期的分解

●procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);

描述:
DecodeDate从一个TDateTime类型参数Date中分解出得到年份、月份、日子。

●procedure DecodeDateDay(const Avalue: TDateTime; out AYear, ADayOfYear: Word);

描述:
DecodeDateDay 方法会根据TDateTime类型参数Avalue 得到相应的年份和日期总数。
ADayOfYear:1月1日,此数值为1;1月2日,此数值为2。

●procedure DecodeDateMonthWeek(const Avalue: TDateTime; out AYear, AMonth, AWeekOfMonth,

ADayOfWeek: Word);

描述:
DecodeDateMonthWeek方法根据TDateTime类型参数Avalue 得到相应的年份、月份、月份中的第几个
星期、星期几
AYear:年份
AMonth:月份,1 到 12
AWeekOfMonth:在该月份中的第几个星期
ADayOfWeek:星期几。星期一为1。

●procedure DecodeDateTime(const Avalue: TDateTime; out AYear, AMonth, ADay, AHour, AMinute,

ASecond, AMilliSecond: Word);

描述:
DecodeDateTime 方法根据TDateTime类型参数Avalue 得到相应的年份、月份、日子、小时、分、秒、
毫秒。

●procedure DecodeDateWeek(const Avalue: TDateTime; out AYear, AWeekOfYear, ADayOfWeek: Word);

描述:
DecodeDateWeek方法根据TDateTime类型参数Avalue 得到相应的年份、在该年中的第几个星期、星期几。

Guess you like

Origin www.cnblogs.com/guorongtao/p/11138703.html