Pergunta

I wanted to use SimpleDateFormat.parse method to set the date:

 private static SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM");
 ...
  Calendar calendar = Calendar.getInstance();
  int year = calendar.get(Calendar.YEAR);
  calendar.setTime(fmt.parse("9-Jul"));
  calendar.set(Calendar.YEAR, year);

but I get:

Exception in thread "main" java.text.ParseException: Unparseable date: "9-Jul"
    at java.text.DateFormat.parse(Unknown Source)
    at BusinessPlan.main(BusinessPlan.java:116)

The code comes from Apache sample site and it is published with this bug.

Foi útil?

Solução

works fine for me

try setting Locale

 SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM", Locale.US);

Outras dicas

I think because you use "dd" you'd have to use 09 instead of 9.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top