delphi中的时间函数运算《转》

delphi中的时间函数运算《转》首先使用 dateutils 单元 即 uses dateutils 有什么不明白的 去查看这个函数的声明 就明白了 yearsbetween 开始时间 结束时间 中间相差多少年 保留整数部分 monthsbetwee 开始时间 结束时间 中间相差多少月

大家好,我是讯享网,很高兴认识大家。

首先使用dateutils单元,即 uses dateutils;// 有什么不明白的,去查看这个函数的声明,就明白了

yearsbetween(开始时间,结束时间)-------------中间相差多少年  保留整数部分

monthsbetween(开始时间,结束时间)-------------中间相差多少月  保留整数部分

daysbetween(开始时间,结束时间)-------------中间相差多少天  保留整数部分

hoursbetween(开始时间,结束时间)-------------中间相差多少小时  保留整数部分 

以此类推 分钟、秒

yearspan(开始时间,结束时间)-------------中间相差多少年  小数表示

monthspan(开始时间,结束时间)-------------中间相差多少月  小数表示

以下以此类推

 

 

 

取日期年份分量

function GetYear(Date: TDate): Integer;  

//取日期月份分量

function GetMonth(Date: TDate): Integer;  

//取日期天数分量

function GetDay(Date: TDate): Integer;  

//取时间小时分量

function GetHour(Time: TTime): Integer;  

//取时间分钟分量

function GetMinute(Time: TTime): Integer;  

//取时间秒分量

function GetSecond(Time: TTime): Integer;  

//取时间毫秒分量

function GetMSecond(Time: TTime): Integer;  

//传入年、月,得到该月份最后一天

function GetMonthLastDay(Cs_Year,Cs_Month:string):string;

//判断某年是否为闰年

function IsLeapYear( nYear: Integer ): Boolean;

//两个日期取较大的日期

function MaxDateTime(const Values: array of TDateTime): TDateTime;

//两个日期取较小的日期

function MinDateTime(const Values: array of TDateTime): TDateTime;

//得到本月的第一天

function dateBeginOfMonth(D: TDateTime): TDateTime;

//得到本月的最后一天

function DateEndOfMonth(D: TDateTime): TDateTime;

//得到本年的最后一天

function DateEndOfYear(D: TDateTime): TDateTime;

//得到两个日期相隔的天数

function DaysBetween(Date1, Date2: TDateTime): Integer;

 

 


讯享网

//=============================================

 

2、function DateTimeToStr(DateTime: TDateTime): string; 描述 DateTimeToString 函数将 TDateTime 类型的参数 DateTime 转换成一个字符串,使用给定的全局变量 ShortDateFormat 的格式,时间部分按照给定的全局变量 LongTimeFormat 的格式。其中 DateTime 为零的部分将不会显示出来。 例如: ShortDateFormat:=yyyy mm dd; showmessage(DateTimetostr((now()))); 你将得到:2003 03 19 10:50:49

3、procedure DateTimeToString(var Result: string; const Format: string; DateTime: TDateTime); 描述: DateTimeToString 方法将TDateTime类型的参数DateTime 按照由参数Format提供的格式转化成字符串,并保存在Result中。对于Format的格式类型,请看 Date-Time format strings 的帮助。 例如: DateTimeToString(result,yyyy mm dd,now()); 那么 result的结果为:2003 03 19 10:50:49

4、procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime); 描述:有时为了调用API函数来使用系统时间,你可以使用 DateTimeToSystemTime 方法,来将一个 TDateTime 类型的时间变量转换成一个 TSystemTime 类型的系统时间。

5、function DateTimeToUnix(const AValue: TDateTime ): Int64; 描述:使用 DateTimeToUnix 函数来将一个 TDateTime 型时间变量转换成一个相应的 Unix 格式的日期和时间。

6、function DateToStr(Date: TDateTime): string; 描述:使用 DateToStr 函数能得到 TDateTime 日期时间类型的日期部分。日期的转换格式依赖于全局变量 ShortDateFormat。

7、function DayOf(const AValue: TDateTime): Word; 描述:对于给定的TDateTime类型的日期时间,使用 DayOf 函数能得到该日期是该月份的第几天。该函数的返回数值在 1 到 31 之间注意:DayOf 函数得到的结果与 DayOfTheMonth 相同。 例如: showmessage(inttostr(dayof(now))); 得到的是:19 (今天是某月19日)

8、function DayOfTheMonth(const AValue: TDateTime): Word; 与 DayOf 相同。

9、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.

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

11、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。这里星期日 是一周的第一天,而星期六是第七天。

12、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 天。

13、function DaysInAMonth(const AYear, AMonth: Word): Word; 描述:对于各定的 年份和月份,DaysInAMonth 函数能得到该月份的总天数。年份应该为 从 1 到 9999 月份应该为 从 1 到 12

14、function DaysInAYear(const AYear: Word): Word; 描述:对于给定的年份,DaysInAYear函数能得到该年份的总天数。年份应该为 1 到 9999。

☆ Month 开头的函数 
18、function MonthOf(const AValue: TDateTime): Word; 描述:根据给定的TDateTime类型的时间日期参数AValue,MonthOf函数能得到该年份的该月份数。 MonthOf返回数值为 1 到 12。注意:MonthOf函数得到的数值与MonthOfTheYear函数相同

22、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 开头的函数 
23、function WeekOf(const AValue: TDateTime): Word; 描述:根据TDateTime类型的日期时间参数AValu,WeekOf函数会得到该星期为一年的第几个星期

☆ Year 开头的函数 
27、function YearOf(const AValue: TDateTime): Word; 描述:根据给定的TDateTime类型的日期时间参数AValue,YearOf函数能得到该日期的年份数字。 YearOf函数返回的数值为从 1 到 9999

☆日期的合成 
31、function EncodeDate(Year, Month, Day: Word): TDateTime; 描述: EncodeDate函数将根据参数 年份、月份、日子而得到一个TDateTime类型的时间变量。

☆日期的分解 
37、procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word); 描述: DecodeDate从一个TDateTime类型参数Date中分解出得到年份、月份、日子。

小讯
上一篇 2025-02-21 18:11
下一篇 2025-02-10 09:18

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/129837.html