DateFormat: parse(String dateString) : DateFormat « java.text « Java by API






DateFormat: parse(String dateString)

 

/*
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.DateFormat.FULL
2.DateFormat.LONG
3.DateFormat.MEDIUM
4.DateFormat.SHORT
5.DateFormat: format(Date date)
6.DateFormat: getAvailableLocales()
7.DateFormat: getDateInstance(int style,Locale aLocale)
8.DateFormat: getDateTimeInstance(int dateStyle, int timeStyle)
9.DateFormat: getTimeInstance(int style,Locale aLocale)
10.DateFormat: setLenient(boolean lenient)