delphi常用日期函数

上传人:ji****72 文档编号:37539856 上传时间:2018-04-18 格式:DOC 页数:6 大小:65.50KB
返回 下载 相关 举报
delphi常用日期函数_第1页
第1页 / 共6页
delphi常用日期函数_第2页
第2页 / 共6页
delphi常用日期函数_第3页
第3页 / 共6页
delphi常用日期函数_第4页
第4页 / 共6页
delphi常用日期函数_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《delphi常用日期函数》由会员分享,可在线阅读,更多相关《delphi常用日期函数(6页珍藏版)》请在金锄头文库上搜索。

1、delphi 常用日期函数 使用单元:uses DateUtils Day 开头的函数开头的函数function DateOf(const AValue: TDateTime): TDateTime; 描述: 使用 DateOf 函数用来把一个 TDateTime 类型的变量转变成一个只带有日期的 TDateTime 类型变量。例如:showmessage(DateTimetostr(dateof(now(); 你得到的是 2003/03/19 而 showmessage(DateTimetostr(now(); 得到的是 2003/03/19 10:50:49function DateTim

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

3、g(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:49procedure DateTi

4、meToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime); 描述: 有时为了调用 API 函数来使用系统时间,你可以使用 DateTimeToSystemTime 方法,来将一个 TDateTime 类型的时间变量转换成一个 TSystemTime 类型的 系统时间。function DateTimeToUnix(const AValue: TDateTime ): Int64; 描述: 使用 DateTimeToUnix 函数来将一个 TDateTime 型时间变量转换成一个相应的 Unix 格式的日期和时 间。Unix

5、 date-and-time values are encoded as the number of seconds that have elapsed since midnight at the start of January 1, 1970.function DateToStr(Date: TDateTime): string; 描述: 使用 DateToStr 函数能得到 TDateTime 日期时间类型的日期部分。日期的转换格式依赖于全局变量 ShortDateFormat。function DayOf(const AValue: TDateTime): Word; 描述: 对于给定

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

7、类型的日期时间,使用 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: TDate

8、Time): 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

9、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. 描述: 按照给定的 TDateTim

10、e 类型的参数 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 分,该函数得到的结果是

11、 0,因为两者之间的时间差别还差 1 分钟才到 1 天。function DaysInAMonth(const AYear, AMonth: Word): Word; 描述: 对于各定的 年份和月份,DaysInAMonth 函数能得到 该月份的总天数。 年份应该为 从 1 到 9999 月份应该为 从 1 到 12function DaysInAYear(const AYear: Word): Word; 描述: 对于给定的年份,DaysInAYear 函数能得到该年份的总天数。 年份应该为 1 到 9999。function DaysInMonth(const AValue: TDateT

12、ime): Word; 描述: 根据给定的 TDateTime 类型的时间日期参数 AValue,DaysInMonth 函数能得到该月份的总天数。function DaysInYear(const AValue: TDateTime): Word; 描述: 根据给定的 TDateTime 类型的时间日期参数 AValue,DaysInYear 函数能得到该年份的总天数。function DaySpan(const ANow, AThen: TDateTime): Double; 描述: 根据两个 TDateTime 类型的日期时间参数 ANow 和 AThen,DaySpan 能得到在天数上

13、的差距。与 DaysBetween 函数不同,DaysBetween 函数 只是计算 整的天数,而 DaySpan 函数会将不足一天的数 也得到。 注意:此函数返回的数值为 Double 型。 Month 开头的函数开头的函数function MonthOf(const AValue: TDateTime): Word; 描述: 根据给定的 TDateTime 类型的时间日期参数 AValue,MonthOf 函数能得到该年份的该月份数。 MonthOf 返回数值为 1 到 12。 注意:MonthOf 函数得到的数值与 MonthOfTheYear 函数相同function MonthOfT

14、heYear(const AValue: TDateTime): Word; 与 MonthOf 函数相同。function MonthsBetween(const ANow, AThen: TDateTime): Integer; 描述: 根据两个给定的 TDateTime 类型的参数 ANow 和 AThen,MonthsBetween 函数能得到两个日期在月份上 差距数。因为月份的天数是不同的,所以 MonthsBetween 函数返回的是一个近似值,该近似值基于每 个月份为 30.4375 天。不足一个月的数字将不被计算。 因此,例如,对于 2 月 1 日 到 2 月 28 日,Mon

15、thsBetween 返回的数值为 0。 同样,对于 2 月 1 日 到 3 月 1 日,MonthsBetween 返回的数值也是 0。function MonthSpan(const ANow, AThen: TDateTime): Double; 描述:根据两个给定的 TDateTime 类型的参数 ANow 和 AThen,MonthsBetween 函数能得到两个日期在月份上 差距数。因为月份的天数是不同的,所以 MonthsBetween 函数返回的是一个近似值,该近似值基于每 个月份为 30.4375 天。与 MonthsBetween 函数不同,MonthsBetween 函数

16、不计算不足一个月的数字, MonthSpan 函数将会得到不足一个月的数字。 注意:此函数返回的类型为 Doublefunction 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 开

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号