A correct way for JAVA age calculation? [closed]
- by Jhonnytunes
I have already a Java calculation of age method. I have a Person Class where I have the method and I need to ask the current time each time the method is called. All I could do is make age a static field of person class, so all person classes use the same time now. Im worring about the Calendar.get() creating Calendar objects every time method is called. Am I doing it wrong? Can I make it better?
public short getAge(){
now = Calendar.getInstance();
return (short) ( (now.getTimeInMillis() - birthDate.getTimeInMillis())/ 31536000000L);
}