Why can't I parse SimpleDateFormat with the "MMMMM dd" pattern in Java?

I need to parse a string like "February 12, 1981" as a date. I am using SimpleDateFormat . But if I do this:

new SimpleDateFormat("MMMMM dd, yyyy").parse("February 12, 1981") 

I get java.text.ParseException.

I tried to reduce it to see where the problem is. Firstly:

 new SimpleDateFormat("MMMMM").parse("February") 

works. Then:

 new SimpleDateFormat("MMMMM dd").parse("February 12") 

does not work any more. Does anyone know why? I also tried new SimpleDateFormat("MMMMM' 'dd") .

I am using JRE 1.6.0_06.

+4
source share
1 answer

What version of JDK / JRE are you using?

This works fine for me with 1.4.2_14, 1.5.0_16 and 1.6.0_07:

 SimpleDateFormat df = new SimpleDateFormat("MMMMM dd, yyyy"); Date parsed = df.parse("February 12, 1981"); System.out.println(parsed); 

output:

Thu Feb 12 00:00:00 EST 1981

+7
source

Source: https://habr.com/ru/post/1277370/


All Articles