Date: after(Date when) : Date « java.util « Java by API






Date: after(Date when)

/*
Mon Jan 01 00:00:00 PST 2001 is after Sat Jan 01 00:00:00 PST 2000
 * */

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MainClass {

  public static void main(String[] a) throws Exception{

    DateFormat df = new SimpleDateFormat ("yyyy-MM-dd");

    Date d1 = df.parse("2001-01-01");

    Date d2 = df.parse("2000-01-01");

    String relation;
    if (d1.equals(d2))
      relation = "the same date as";
    else if (d1.before(d2))
      relation = "before";
    else if (d1.after(d2))
      relation = "after";
    System.out.println(d1 + " is " + relation + ' ' + d2);
  }
}

           
       








Related examples in the same category

1.new Date()
2.new Date(int intValue)
3.Date: before(Date when)
4.Date: diff (Not a method)
5.Date: equals(Object anotherDate)
6.Date: getTime()
7.Date: setTime(long miliseconds)