Pergunta

This is my first time using Joda-Time. Why does the month default to January? It doesn't matter what month values i enter as date including (1-12) or (Jan-Dec). All default to January.

DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/DD HH:mm:ss");
DateTime issuedTimeStamp = fmt.parseDateTime("2014/04/30 08:23:36");

System.out.println("Issued: " + issuedTimeStamp.toString()); 
//above prints `2014-01-30T08:23:36.000-05:00`

Ive checked my pattern which seems right. Where am i going wrong? Thank you.

Foi útil?

Solução

You're using DD in your format string, which means "day of year". So after parsing the month as April, you're then going to the 30th day of the year, which is in January... You want dd, for "day of month".

When in doubt, if a format string doesn't do what you expect:

  • Check every format specifier against the documentation
  • Check that you're escaping everything you should
  • Try formatting a hard-coded value (ideally similar to one that's failing to parse)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top