get Age From Date - Android java.util

Android examples for java.util:Date Algorithm

Description

get Age From Date

Demo Code

import java.util.Calendar;

public class Main{

    public static int getAgeFromDate(long birthDate) {
        long msYear = 1000L * 60 * 60 * 24 * 365;
        int years = (int) ((getUnixTime() - birthDate) / msYear);
        return years;
    }/*from  w  w  w.j a  v  a2 s  .c  om*/
    public static long getUnixTime() {
        return Calendar.getInstance().getTime().getTime();
    }
}

Related Tutorials