I have 2 Calendar objects for the current date and birthdate. I need to subtract birthdate from the current date and return the difference in years (a truncated Int is all I need).
What's the simplest way of doing this?
I have 2 Calendar objects for the current date and birthdate. I need to subtract birthdate from the current date and return the difference in years (a truncated Int is all I need).
What's the simplest way of doing this?
You can get EPOCH time (miliseconds since 01.01.1900), subtract both values and divide it by 1000(miliseconds)/60(seconds)/60(minutes)/24(hours)/365(days)
.
This would give you approximate result (in years) because of ignoring leap years.
To get epoch time, use Date#getTime()
;