Pregunta

DateTime start = DateTimeFormat.forPattern("dd/mm/yyyy").parseDateTime("30/08/2012");

I added 10 days into start date above, but it does not switch to the next month. However, the code below will.

DateTime start = DateTimeFormat.forPattern("dd/MM/yyyy").parseDateTime("30/08/2012");

Why ?

¿Fue útil?

Solución

You are mixing minutes (mm) and months (MM). From the DateTimeFormat javadoc:

 Symbol  Meaning                      Presentation  Examples
 ------  -------                      ------------  -------
 M       month of year                month         July; Jul; 07
 m       minute of hour               number        30

The same pattern symbols are by the way also used on Java SE's own SimpleDateFormat class.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top