I have a date object that holds a persons birthday. My code looks like:
def getAge(){
//birthday, birthYear, birthMonth, birthDayOfMonth are class level properties
def c= new GregorianCalendar(birthYear, birthMonth-1, birthDayOfMonth)
birthday = c.time
//What do I do now?
}
I need to return the age of the person. How do I do that in Groovy? The age only needs to be a integer.
You can just create one calendar with the current date and use the year to compute age:
the fake date is used to understand if birthday is already passed in current year, if it’s not then you must substract 1 to the difference between years..