-1

I need to convert a string ( 20-04-2014) to date in the format DD-MM-YYYY of type date.

String date = "20-04-2014";

I need to convert it to a type Date. How to do this??

2 Answers2

0

You can use SimpleDateFormat class like this.

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
    String dateString = "20-04-2014";
    Date date = formatter.parse(dateString );

look here for sample

Prabhaker A
  • 8,317
  • 1
  • 18
  • 24
0

You can use SimpleDateFormat to implement.

Refer to http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

    String date = "20-04-2014";

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    Date d = sdf.parse(date);
Mengjun
  • 3,159
  • 1
  • 15
  • 21