ImageVerifierCode 换一换
格式:DOCX , 页数:64 ,大小:27.01KB ,
资源ID:3393506      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3393506.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Delphi 常用日期与时间函数.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Delphi 常用日期与时间函数.docx

1、Delphi 常用日期与时间函数Delphi 常用日期与时间函数1 获取特定的日期与时间本小节将为您介绍Delphi 所提供的获取特定日期与时间的函数.这些函数稍后将有详细的范例说明.笔者这里将以列表的方式先说明每一个函数所代表的意义,如图示:函数名称单元文件所代表的意义NowSysUtils此函数可返回现在的日期与时间,其返回值为TDateTime类型DateSysUtils此函数可返回现在的日期,其返回值为TDateTime类型TimeSysUtils此函数可返回现在的时间,其返回值为TDateTime类型TodayDateUtils此函数可返回今天的日期,其返回值为TDateTime类型

2、,此函数的结果与Date函数相同.TomorrowDateUtils此函数可返回昨天的日期,其返回值为TDateTime类型YesterdayDateUtils此函数可返回明天的日期,其返回值为TDateTime类型CurrentyearSysUtils此函数可返回现在所属的年度,其返回值为4的整数.例如:2001HoursperdaySysUtils此常数定义每天的小时数.HoursPerDay =24;MinsperdaySysUtils此常数定义每天的分钟数.MinsPerDay = MinsPerDay*60SecsperdaySysUtils此常数定义每天的秒数.SecPerDay

3、= MinsPerDay *60msecsperdaySysUtils此常数定义每天的毫秒数.MSecsPerDay =SecsperDay*1000Now (返回当前的日期时间)引用单元:SysUtils函数声明:Function Now : TDateTime;范例D-1Procedure TForm1.Button1Click(Sender: TObject);VarMyDateTime : TDateTime;beginMyDateTime :=Now; Showmessage(DateTimeToStr(MyDateTime);end;Date(返回当前的日期)引用单元:SysUti

4、ls函数声明:Function Day :TDateTime;范例D-2Procedure TForm1.Button1Click(Sender: TObject);VarMyDateTime : TDateTime;beginMyDateTime :=Date; Showmessage(DateTimeToStr(MyDateTime);end;Time(返回当前的时间)引用单元:SysUtils函数声明:Function Time:TDateTime;范例D-3Procedure TForm1.Button1Click(Sender: TObject);VarMyDateTime : TD

5、ateTime;beginMyDateTime :=Time; Showmessage(DateTimeToStr(MyDateTime);end;Today(返回今天的日期)引用单元:DateUtils函数声明:Function Today :TDateTime;范例D-4Procedure TForm1.Button1Click(Sender: TObject);VarMyDateTime : TDateTime;Begin/uses DateUtilsMyDateTime :=Today; Showmessage(DateTimeToStr(MyDateTime);end;Tomorro

6、w(返回明天的日期)引用单元:DateUtils函数声明:Function Tomorrow:TDateTime;范例D-5Procedure TForm1.Button1Click(Sender: TObject);VarMyDateTime : TDateTime;Begin/uses DateUtilsMyDateTime :=Tomorrow; /MyDateTime : Now +1; /两者相同Showmessage(DateTimeToStr(MyDateTime); /不包含时间部分end;Yesterday(返回昨天的日期)引用单元:DateUtils函数声明:Functio

7、n Yesterday :TDateTime;范例D-6Procedure TForm1.Button1Click(Sender: TObject);VarMyDateTime : TDateTime;Begin/uses DateUtilsMyDateTime :=Yesterday; /MyDateTime : Now -1; /两者相同Showmessage(DateTimeToStr(MyDateTime); /不包含时间部分end;CurrentYear(返回现在所属的年度)引用单元:SysUtils函数声明:Function CurrentYear :Word;范例D-7Proce

8、dure TForm1.Button1Click(Sender: TObject);VarThisYear: Word;Beginthis year := CurrentYear;Showmessage(IntToStr(ThisYear); / 4位整数end;HoursPerDay,MinsPerDay,SecsPerDay及MsecsPerDay等日期与时间常数.引用单元:SysUtils函数声明:Function CurrentYear:Word;范例D-8Procedure TForm1.Button1Click(Sender: TObject);BeginShowmessage(每

9、天的小时数= + IntToStr(HoursperDay); /24 Showmessage(每天的分钟数= + IntToStr(MinsperDay); / 1440Showmessage(每天的秒数= + IntToStr(SecsperDay); /24 Showmessage(每天的毫秒数= + IntToStr(MSecsperDay); /24 end;D.2 日期处理函数:函数名称单元文件所代表的意义YearOfDateUtils此函数可获取TDateTime格式中的年度,其返回值为Word类型.YearsBeTweenDateUtils此函数可返回两个指定日期间的年份,一年

10、以365.25天为计算单位.其返回值不包含小数部分YearSpanDateUtils此函数可返回两个指定日期间的年份,一年以365.25天为计算单位.其返回值包含小数部分StartOfAYearDateUtils此函数可返回特定年份的第一天EndOfAYearDateUtils此函数可返回特定年份的最后一天StrtOfTheYearDateUtils此函数可返回特定日期的该年第一天EndOfTheYearDateUtils此函数可返回特定日期的该年最后一天IncYearDateUtils此函数可将指定的TDateTime变量加上指定的年度,其默认值为1年MonthOfDateUtils此函数可

11、获取TDateTime格式中的月份,其返回值为Word类型MonthOfTheYearDateUtils此函数可获取TDateTime格式中的月份,其返回值为Word类型MonthBetweenDateUtils次函数可返回两个指定日期间的月份数,一个月以30.4375天为计算单位.其返回值不包含小数部分MonthSpanDateUtils次函数可返回两个指定日期间的月份数,一个月以30.4375天为计算单位.其返回值包含小数部分StartOfAMonthDateUtils此函数可返回特定年月的第一天EndOfAMonthDateUtils此函数可返回特定年月的最后一天StartOfTheMo

12、nthDateUtils此函数可返回指定日期的该年的第一天EndOfTheMonthDateUtils此函数可返回指定日期的该年的最后一天IncMonthDateUtils此函数可将指定的TDateTime变量加上指定的月份,其默认值为加上1个月IncAMonthDateUtils此函数可将指定的年月日加上指定的月份,其默认值为加上1个月DaysInAYearDateUtils此函数可返回指定年份的总天数DaysInYearDateUtils此函数可返回指定TDateTime变量中该年分的总天数DaysInAMonthDateUtils此函数可返回指定月份的总天数DaysInMonthDate

13、Utils此函数可返回指定TDateTime变量中该月份的总天数DaysOfDateUtils此函数可获取TDateTime格式中的日期,其返回值为Word类型DaysBetweenDateUtils此函数可获取格式中的日期,其返回值不包含小数部分DaySpanDateUtils此函数可返回两个指定日期间的天数,其返回值包含小数部分DayOfTheYearDateUtils此函数可返回指定TDateTime变量为该年的第几天.例如2月1日则返回32DayOfTheMonthDateUtils此函数可返回指定TDateTime变量为该月的第几天,其返回值介于1到31DayOfTheWeekDat

14、eUtils此函数可返回指定TDateTime变量为该周的第几天,其返回值介于1到7.星期一为第一天.DayOfWeekDateUtils此函数可返回指定TDateTime变量为该周的第几天,其返回值介于1到7.星期日为第一天.StartOfADayDateUtils此函数可返回指定日期一天的开始时间,其返回值为TDateTime类型.其时间默认为12:00:000 AMEndOfADayDateUtils此函数可返回指定日期一天的结束时间,其返回值为TDateTime类型.其时间默认为11:59:999 PMStartOfTheDayDateUtils此函数可返回指定TDateTime变量的

15、一天开始时间,其返回值为TDateTime类型.其时间默认为:12:00:000 AMEndOfTheDayDateUtils此函数可返回指定TDateTime变量的一天结束时间,其返回值为TDateTime类型.其时间默认为11:59:999PMIncDayDateUtils此函数可为指定日期加上特定的天数,其返回值为TDateTime类型,其默认天数为1天WeeksInAYearDateUtils此函数可返回指定年度的周数,其返回值不是52就是53WeeksInYearDateUtils此函数可返回指定TDateTime变量的周数,其返回值不是52就是53WeekOfDateUtils次函

16、数可返回指定日期为该年的第几周,其返回值为153WeekOfTheYearDateUtils次函数可返回指定日期为该年的第几周,其返回值为153WeekOfTheMonthDateUtils次函数可返回指定日期为该月的第几周,其返回值为16WeeksBetweenDateUtils此函数可返回两个指定日期间的周数,其返回值不包含小数部分WeekSpanDateUtils此函数可返回两个指定日期间的周数,其返回值包含小数部分StartOfAweekDateUtils此函数可返回指定日期一周的开始时间,其返回值为TDateTime类型.其时间默认为12:00:000 PMEndOfAWeekDat

17、eUtils此函数可返回指定日期一周的结束时间,其返回值为TDateTime类型.其时间默认为11:59:999 PMStartOfTheWeekDateUtils此函数可返回指定TDateTime变量的一周开始时间,其返回值为TDateTime类型.其其时间默认为12:00:000 AMEndOfTheWeekDateUtils此函数可返回指定TDateTime变量的一周结束时间,其返回值为TDateTime类型.其时间默认为11:59:999 AMIncWeekDateUtils此函数可将指定日期加上指定周数,其返回值为TDateTime类型YearOf(返回指定日期的年度)引用单元:Da

18、teUtils函数声明:Function YearOf ( const AValue : TDateTime) :Word;范例D-9Procedure TForm1.Button1Click(Sender: TObject);Begin/三者都相同Showmessage(年度= + IntToStr(YearOf(Now); Showmessage(年度= + IntToStr(YearOf(Date); Showmessage(年度= + IntToStr(YearOf(Today); end;YearsBetween(返回两个指定日期间的年份)引用单元:DateUtils函数声明:Fun

19、ction YearsBetween ( const ANow, AThen : TDateTime) :Integer;范例D-10Procedure TForm1.Button1Click(Sender: TObject);Begin/不包含小数,一年以365.25天为计算单位Showmessage(几年= + IntToStr(YearsBetween(Now,Now+560); /1end;YearSpan(返回两个指定日期间的年份)引用单元:DateUtils函数声明:Function YearsSpan( const ANow , AThen : TDateTime) :Doubl

20、e;范例D-11Procedure TForm1.Button1Click(Sender: TObject);Begin/包含小数,一年以365.25天为计算单位Showmessage(几年= + FloatToStr(YearSpan(Now,Now+560);/1.53.end;StartOfAYear(返回特定年份的第一天)引用单元:DateUtils函数声明:Function StartOfAYear ( const AYear) : TDateTime;范例D-12Procedure TForm1.Button1Click(Sender: TObject);BeginShowmess

21、age(DateTimeToStr(StartOfAYear(2001);/2001/1/1 早上12:00:00end;EndOfAYear(返回特定年份的最后一天)引用单元:DateUtils函数声明:Function EndOfAYear ( const AYear) : TDateTime;范例D-13Procedure TForm1.Button1Click(Sender: TObject);BeginShowmessage(DateTimeToStr(EndOfAYear(2001);/2001/12/31 下午11:59:59end;StartOfTheYear(返回指定日期的该

22、年的第一天)引用单元:DateUtils函数声明:Function StartOfTheYear ( const AValue : TDateTime) :TDateTime;范例D-14Procedure TForm1.Button1Click(Sender: TObject);BeginShowmessage(DateTimeToStr(StarOfTheYear(Now);/指定的年度/1/1早上12:00:00end;EndOfTheYear(返回指定日期的该年的最后一天)引用单元:DateUtils函数声明:Function EndOfTheYear ( const AValue :

23、 TDateTime) :TDateTime;范例D-15Procedure TForm1.Button1Click(Sender: TObject);BeginShowmessage(DateTimeToStr(StarOfTheYear(Now);/指定年度/12/31下午11:59:59end;IncYear(将指定的TDateTime变量加上指定的年)引用单元:DateUtils函数声明:Function IncYear ( const AValue : TDateTimel; const ANumberOfYears : Integer =1) :TDateTime;范例D-16 P

24、rocedure TForm1.Button1Click(Sender: TObject);varmyDateTime : TDateTime;BeginmyDateTime : = IncYear(Now,3); /往后加3年Showmessage(DateTimeToStr(myDateTime);End;MonthOf(获取TDateTime格式中的月份)引用单元:DateUtils函数声明:Function MonthOf ( const AValue : TDateTime) :Word;范例D-17 Procedure TForm1.Button1Click(Sender: TOb

25、ject);varmyDateTime : TDateTime;m : Integer;BeginmyDateTime : = Now; /两个函数获取相同的结果m := MonthofTheYear(myDateTime);Showmessage(IntToStr(m);end;MonthOfTheYear(获取TDateTime格式中的月份)引用单元:DateUtils函数声明:Function MonthOfTheYear ( const AValue : TDateTime) :Word;范例D-18 Procedure TForm1.Button1Click(Sender: TObj

26、ect);vari :Integer;f :Double;Begini := MonthsBetween(Now,Now+89);/差89天Showmessage(IntToStr(i);/2f := MonthSpan(Now,Now+89);/差89天Showmessage(FloatToStr(f);/2.924End;MonthsBetween(返回两个指定日期间的月份数)引用单元:DateUtils函数声明:Function MonthsBetween ( const ANow, AThen : TDateTime) :Integer;MonthSpan(返回两个指定日期间的月份数)

27、引用单元:DateUtils函数声明:Function MonthSpan ( const ANow, AThen : TDateTime) :Double;StartOfAMonth(返回特定年月的第一天)引用单元:DateUtils函数声明:Function StartOfAMonth ( const AYear, AMonth : Word) : TDateTime;EndOfAMonth(返回特定年月的最后一天)引用单元:DateUtils函数声明:Function EndOfTheMonth ( const AYear, AMonth : Word) : TDateTime;Star

28、tOfTheMonth(返回特定年月的第一天)引用单元:DateUtils函数声明:Function StartOfTheMonth ( const AValue : TDateTime) :TDateTime;EndOfTheMonth(返回特定年月的最后一天)引用单元:DateUtils函数声明:Function EndOfTheMonth ( const AValue : TDateTime) :TDateTime;范例D-19varmyDateTime :TDateTime;Year,Month :Integer;BeginYear := YearOf(Now);Month :=Mon

29、thOf(Now);/找出当前月份的第一天myDateTime := StartOfAMonth(Year,Month);Showmessage(DateTimeToStr(myDateTime);/找出当前月份的最后一天myDateTime := EndOfAMonth(Year,Month);Showmessage(DateTimeToStr(myDateTime);/找出当前月份的第一天myDateTime := StartOfTheMonth(Now);Showmessage(DateTimeToStr(myDateTime);/找出当前月份的最后一天myDateTime := End

30、OfTheMonth(Now);Showmessage(DateTimeToStr(myDateTime);end;IncMonth(指定的TDateTime变量加上指定的月份)引用单元:DateUtils函数声明:Function IncMonth ( const Date : TDateTime ; NumberOfMonths : Integer = 1) :TDateTime;IncAMonth(指定的年月日变量加上指定的月份)引用单元:DateUtils函数声明:Procedure IncAMonth ( Var Year, Month , Day : Word ; NumberOfMonths : Integer =1 );范例D-20varmyDateTime :TDateTime;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1