[ Back | Previous | Next ]

Parsing a string containing a date in format 'dd-mm-yy' to a Date

Package:
java.text.*
Product:
JDK
Release:
1.1.x
Related Links:
DateFormat
DecimalFormat
NumberFormat
SimpleDateFormat
Comment:
Parsing a string containing a date in format 'dd-mm-yy' to a Date 

public static String toEDIDate(java.sql.Date o) {
	StringBuffer date = new SimpleDateFormat("yyMMdd").format(o, new StringBuffer(), new FieldPosition(0));
	return date.toString();
}
      public Date getDate( String token ) {
              Date visited; 
              SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yy"); 
              ParsePosition pos;
              try {                            
                      pos = new ParsePosition(0);
                      visited = sdf.parse(token,pos);
              } catch (NullPointerException pe) {
                      System.out.println("Cannot parse visited date! " + token ); 
                      pos = new ParsePosition(0);
                      visited = sdf.parse("16/06/97", pos);
              }
      }
1