文档详情

[Delphi] 常用日期函数.doc

发布:2017-04-26约8.62千字共6页下载文档
文本预览下载声明
Use 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:49 ●function DateTimeToStr(DateTime: TDateTime): string; 描述:DateTimeToString 函数将 TDateTime 类型的参数 DateTime 转换成一个字符串,使用给定的全局变量 ShortDateFormat 的格式,时间部分按照给定的全局变量 LongTimeFormat 的格式。其中 DateTime 为零的部分将不会显示出来。 例如: ShortDateFormat:=yyyy mm dd; showmessage(DateTimetostr((now()))); 你将得到:2003 03 19 10:50:49 ●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 ●procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime); 描述:有时为了调用API函数来使用系统时间,你可以使用 DateTimeToSystemTime 方法,来将一个TDateTime 类型的时间变量转换成一个 TSystemTime 类型的 系统时间。 ●function DateTimeToUnix(const AValue: TDateTime ): Int64; 描述:使用 DateTimeToUnix 函数来将一个 TDateTime 型时间变量转换成一个相应的 Unix 格式的日期和时间。 Unix 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; 描述:对于给定的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类型的日期时间,使用 DayOfTheWeek 函数能得到该日期是该星期的第几天。DayOfTheWeek 函数的返回数值为 1 到 7,其中 1 表示星期一,而 7 表示星期日。 注意:DayOfTheWeek 是 ISO 8601 标准的(此标准为 星期一是一周的第一天)。对于一周 的第一天是星期日的标准,如果想获得星期数,请使用 DayOfWeek 函数。 Tip: To make the return
显示全部
相似文档