Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { private static final SimpleDateFormat FORMATTER1 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH); public static String getAdAgeInDays(final String adDate) throws ParseException { return "" + getDaysBetweenDates(FORMATTER1.parse(adDate), new Date()); } /** * @param date1 -past date * @param date2 -future date than date1 * @return total days between Dates */ private static int getDaysBetweenDates(Date date1, Date date2) { return (int) ((date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24l)); } }