If a date is before another date
import java.util.Calendar; import java.util.Date; public class Main { public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); Date yesterday = calendar.getTime(); if (yesterday.before(today)) { System.out.println(yesterday + " is before " + today); } } }