public Date next() { if (isValid(month, day + 1, year)) return new Date(month, day + 1, year); else if (isValid(month + 1, 1, year)) return new Date(month + 1, 1, year); else return new Date(1, 1, year + 1); }
public boolean isAfter(Date b) { return compareTo(b) > 0; }
public boolean isBefore(Date b) { return compareTo(b) < 0; }
public int compareTo(Date b) { if (year != b.year) return year - b.year; if (month != b.month) return month - b.month; return day - b.day; }
public String toString() { return day + "-" + month + "-" + year; }
public static void main(String[] args) { Date today = new Date(9, 30, 2010); System.out.println(today); Date nextDate = today.next(); System.out.println(nextDate); System.out.println(today.isAfter(nextDate)); System.out.println(today.next().isAfter(today)); System.out.println(today.isBefore(nextDate)); System.out.println(nextDate.compareTo(today)); } }