Java Date get recent date between two date values
import java.time.Instant; import java.util.Calendar; import java.util.Date; public class Main { public static void main(String[] argv) { Date one = Date.from(Instant.EPOCH); Date two = new Date(); System.out.println(maxDate(one, two)); }/*www .j ava 2s . com*/ public static Date maxDate(Date one, Date two) { if (compareDate(one, two) > 0) { return two; } else { return one; } } public static long compareDate(Date start, Date end) { long temp = 0; Calendar starts = Calendar.getInstance(); Calendar ends = Calendar.getInstance(); starts.setTime(start); ends.setTime(end); temp = ends.getTime().getTime() - starts.getTime().getTime(); return temp; } }