Java Date get smaller Date

Description

Java Date get smaller Date

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(minDate(one, two));
  }/*from  w w w .  j  a  v a 2  s . co m*/
  public static Date minDate(Date one, Date two) {
    if (compareDate(one, two) > 0) {
      return one;
    } else {
      return two;
    }
  }

  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;
  }
}



PreviousNext

Related