用于时间操作的函数

Date函数:

定义:Date: TDateTime;

作用:返回当前的日期

范例:CurrentDate := Date;
DayOfWeek函数:

定义:function DayOfWeek(Date: TDateTime): Integer;

作用:得到指定日期的星期值,返回1~7,代表周日到周六。
IncMouth函数:
定义:function IncMonth(const Date: TDateTime; NumberOfMonths: Integer): TDateTime;

作用:求给定的日期Data在NumberOfMonth 个月后的日期。

范例:Date1 := IncMonth(date,10);

如果今天是2002-5-3,则Date1就是2003-3-3

IsLeapYear函数:
定义:function IsLeapYear(Year: Word): Boolean;

作用:判断指定的年份是否是闰年;

范例:if isLeapYear(2000) then ShowMessage(‘该年是闰年’);

Now函数:

定义:function Now: TDateTime;
作用:用于取得当前的日期时间

范例:CurrentDateTime := Now;

ReplaceDate 过程

定义:procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime);

作用:使用参数Newdate日期部分替换参数DateTime的日期部分,但不改变时间部分
ReplaceDate 过程

定义:procedure ReplaceTime(var DateTime: TDateTime; const NewTime: TDateTime);

作用:使用参数Newdate时间部分替换参数DateTime的时间部分,但不改变日期部分。

如果上述这两个过程一起用,就相当于赋值了。
Time函数:

定义:function Time: TDateTime;

作用:返回当前的时间

范例:CurrentTime := Time;
DateTimeToFileDate函数:

定义:DateTimeToFileDate(DateTime: TDateTime): Integer;

作用:将一个TDateTime类型的时间转化为Dos环境中的时间,Dos环境下对时间的访问方法和VCL中的TdateTime类型不一样,在进行文件操作时,为了保持时间的一致性,需要使用DateTimeToFileDate函数进行转化,返回的Integer的值就是Dos下的用于描述时间的值。

DateTimeToSystemTime 过程:

定义:procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);

作用:将一个TDateTime类型的时间转换为Win API函数所使用的TSystemTime类型,在使用WinApi函数操纵时间时用到。

SystemTimeToDateTime 函数:

定义:function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;

作用:将一个在WinApi函数中得到的TSysTemTime类型的数转换为TDateTime类型。

DateTimeToTimeStamp 函数:

TimeStampToDateTime 函数:

定义:DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;

function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;

作用:用于在TDataTime类型与TTimeStamp之间进行互相转换。TDataTime 用一个double描绘一个时间,而TTimeStamp则是采用两个整形数分别描述时间。两种类型的区别可参考文章开始处的数据类型描述部分。

EncodeDate 函数:

定义:function EncodeDate(Year, Month, Day: Word): TDateTime;

作用: 输入年(year),月(month),日(day)的值,将该日期返回为TDateTime类型,年的范围为1-9999,月份的范围为1-12,日期的范围视当月的情况而定,如果输入的值超出范围,则将产生一个EConvertError错误。
DecodeDate 过程:

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

作用:输入一个TDateTime类型的日期,将其转为年(Year),月(Month),日(Day)的值。如果输入值为0或小于0,则年月日均为0,

EncodeTime 函数:

定义:EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;

作用:输入小时(Hour),分(min),秒(Sec),微秒(MSec)的值,返回一个TDateTime类型的时间,该值为一个介于0至1之间的小数。Hour的取值范围为0-23,Min的取值范围为0-59,Sec的取值范围为0-59,MSec的取值范围为0-999,如果输入值超出范围,则产生一个EConvertError 错误。

DecodeTime 过程:

定义:procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);

作用:输入一个时间,将其转换为小时(Hour),分(min),秒(Sec),微秒(MSec)的值。
TDateTime类型与字符串型转换函数:

DateTimeToStr 函数:

DateToStr 函数

TimeToStr函数

定义:function DateTimeToStr(DateTime: TDateTime): string;

function TimeToStr(Time: TDateTime): string;

function TimeToStr(Time: TDateTime): string;

作用:将一个TDateTime类型的数转换成字符串,DateTimeToStr转换日期和时间,DateToStr只转换日期,TimeToStr只转换时间。转换后的输出效果为YYYY-M-D H:M:S

StrToDateTime函数

StrToDate函数

StrToTime函数

定义:function StrToDateTime(const S: string): TDateTime;

function StrToDate(const S: string): TDateTime;

//for   Delphi6   DateUtils.pas  
  {   Range   query   functions   }  
   
  function   YearsBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   MonthsBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   WeeksBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   DaysBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   HoursBetween(const   ANow,   AThen:   TDateTime):   Int64;  
  function   MinutesBetween(const   ANow,   AThen:   TDateTime):   Int64;  
  function   SecondsBetween(const   ANow,   AThen:   TDateTime):   Int64;  
  function   MilliSecondsBetween(const   ANow,   AThen:   TDateTime):   Int64;


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值