Thursday, 15 April 2010

calendar - age calculation in Java -



calendar - age calculation in Java -

this question has reply here:

how calculate someone's age in java? 23 answers

i'm trying create little command line java app allow input of date , compare current date , homecoming integer represents number of years between entered date , current date. calculate age of living person in years. far, i've found need utilize calendar object, can't figure out how subtract entered year current year , homecoming integer. can help? nail high points on mechanics of comparing dates. thanks.

once have calendar object initialized right date, can phone call get(calendar.year) value integer representing year. both dates , subtract.

you'll want month , date , compare, because if end date has lower month/date start, you'll want subtract 1 before result (the year has not yet been completed).

typically birthdays don't care time component (hour/minute/second), libraries may give different result (in extremely little number of cases) -- it's justifiable roll own case.

java calendar

No comments:

Post a Comment