Util.java Source code

Java tutorial

Introduction

Here is the source code for Util.java

Source

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;

public class Util {
    public static final long MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
    public static final long MILLIS_PER_YEAR = 365 * MILLIS_PER_DAY;

    public static int getAge(Date birthDate) {
        if (birthDate == null)
            return 0;
        long ageMillis = System.currentTimeMillis() - birthDate.getTime();
        return (int) (ageMillis / MILLIS_PER_YEAR);
    }
}