求如何计算一个人的年龄,能得到多少岁多少月零几天的方法?
呵呵,有没有现成的函数可用?
[解决办法]
- Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);var year,mon,day,year1,mon1,day1:word; i,j,m,n:integer;begin DecodeDate(Date,year,mon,day); DecodeDate(StrToDate('1980-12-15'),year1,mon1,day1); i:=year-year1; if (mon-mon1<0) or ((mon-mon1=0) and (day<day1)) then i:=i-1;//相差年数 j:=12-mon1+mon; if day<day1 then j:=j-1;//相差月数 m:=Abs(day-day1); Self.Label1.Caption:='你出生 '+inttostr(i)+' 年 '+inttostr(j)+' 个月零 '+inttostr(m)+' 天';end;
[解决办法]
有出生日期就行了
你呱呱落地的日期是:Birthday
DecodeDate(Now-Birthday,Y,M,D)
你生活了:inttostr(Y)+'年'+inttostr(M)+'月'+inttostr(D)+'日'