Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to compare two dates like (before or after a particular date) in J2ME
Posted

1 solution

How about this:
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CompareDates {
  public static void main(String[] args) throws ParseException {

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

    // Get Date 1
    Date d1 = df.parse("2000-02-01");

    // Get Date 2
    Date d2 = df.parse("2001-03-02");

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


Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900