Android examples for java.util:Date Compare
compare date in yyyy-MM-dd format
import java.text.DateFormat; import java.text.SimpleDateFormat; public class Main { public static long compare_date(String DATE1, String DATE2) { long days = 0; DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try {//from w w w . j a va2 s. c o m java.util.Date dt1 = df.parse(DATE1); java.util.Date dt2 = df.parse(DATE2); long diff = dt2.getTime() - dt1.getTime(); days = diff / (1000 * 60 * 60 * 24); } catch (Exception exception) { exception.printStackTrace(); } return days; } }