Java Data Type How to - Parse '29-July-2012' to Date








Question

We would like to know how to parse '29-July-2012' to Date.

Answer

/*from   ww  w  . ja  v  a2s.c o m*/
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Main {

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

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy", Locale.ENGLISH);
    System.out.println(sdf.parse("29-July-2012"));

  }

}

The code above generates the following result.