level 9
0.
非教程,仅是新手的经验交流
1.无存档,所以更新会非常慢
2.仅涉及其中函数&&过程
3.随时欢迎支持错误
4.建议【只看楼主】
2014年09月21日 08点09分
1
level 9
=========================CompareDate=========================
函数原型:Function CompareDate(const A: TDateTime;const B: TDateTime):TValueRelationship
作用:比较日期
备注:比较时忽略时间。即:a年b月c日d时与a年b月c日e时比较是相等的。
返回值:1)小于0。表示a比b早;
2)等于0。a和b是同一日;
3)大于0。表示a比b晚。
2014年09月21日 08点09分
4
level 9
(续上)
例程:
uses sysutils,dateutils;
const fmt=*dddd dd mmmm yyyy*;
procedure test(d1,d2:tdatetime);
var cmp:integer;
begin
write(formatdatetime(fmt,d1),* is *);
cmp:=comparedate(d1,d2);
if cmp<0 then write(*earlier than *) else if cmp>0 then write(*later than *) else write(*equal to *);
writeln(formatdatetime(fmt,d2));
end;
var d,n:tdatetime;
begin
d:=today;
n:=now;
test(d,d);
test(n,n);
test(d+1,d);
test(d-1,d);
test(d+onesecond,d);
test(d-onesecond,d);
test(n+onesecond,n);
test(n-onesecond,n);
end.
2014年09月21日 08点09分
5
level 9
=========================CompareDateTime=========================
函数原型:Function CompareDateTime(Const A,B:TDateTime):TValueRelationship;
作用:比较日期时间
备注:比较时会同时考虑到日期和时间。a年b月c日d时与a年b月c日e时比较是不相等的。
返回值:1)小于0。表示a比b早;
2)等于0。a和b是同一
毫秒;
3)大于0。表示a比b晚。
例程:
uses sysutils,dateutils;
const fmt=*dddd dd mmmm yyyy hh:nn:ss.zzz*;
procedure test(d1,d2:tdatetime);
var cmp:integer;
begin
write(formatdatetime(fmt,d1),* is *);
cmp:=comparedatetime(d1,d2);
if cmp<0 then write(*earlier than *) else if cmp>0 then write(*later than *) else write(*equal to *);
writeln(formatdatetime(fmt,d2));
end;
var d,n:tdatetime;
begin
d:=today;
n:=now;
test(d,d);
test(n,n);
test(d+1,d);
test(d-1,d);
test(d+onesecond,d);
test(d-onesecond,d);
test(n+onesecond,n);
test(n-onesecond,n);
end.
2014年09月21日 09点09分
7
更正:如果返回值是0表示的应该是a的年、月、日、时、分、秒和毫秒与b是完全相等的
2014年09月21日 09点09分
level 9
=========================CompareTime=========================
函数原型:Function CompareTime(Const A,B: TDateTime):TValueRelationship;
作用:比较时间
备注:比较时忽略日期。a年b月c日d时e分f秒g毫秒和h年i月j日d时e分f秒g毫秒比较是相等的。
返回值:1)小于0。表示a比b早;
2)等于0。a和b是同时、分、秒和毫秒(但年月日不一定相等);
3)大于0。表示a比b晚。
例程:
uses sysutils,dateutils;
const fmt=*dddd dd mmmm yyyy hh:nn:ss.zzz*;
procedure test(d1,d2:tdatetime);
var cmp:integer;
begin
write(formatdatetime(fmt,d1),* is *);
cmp:=comparetime(d1,d2);
if cmp<0 then write(*earlier than *) else if cmp>0 then write(*later than *) else write(*equal to *);
writeln(formatdatetime(fmt,d2));
end;
var d,n:tdatetime;
begin
d:=today;
n:=now;
test(d,d);
test(n,n);
test(d+1,d);
test(d-1,d);
test(d+onesecond,d);
test(d-onesecond,d);
test(n+onesecond,n);
test(n-onesecond,n);
end.
2014年09月21日 09点09分
8
level 9
=========================DateOf=========================
函数原型:Function DateOf(Const AValue:TDateTime):TDateTime;
作用:提取日期的部分
备注:参数和返回值的类型都是TDateTime
返回值:调用时参数的日期部分
例程:
USES SysUtils,DateUtils;
BEGIN
WriteLn(*Date is: *,DateTimeToStr(DateOf(Now)));
END.
2014年09月21日 09点09分
9