user1851487
user1851487

Reputation: 547

Joda-Time Invalid format when parsing

Joda-Time complaining that my input is malformed but i am using the same format option:

'd-M-y'

in both the input and the Joda-Time formatter.

DateTimeFormatter formatter = DateTimeFormat.forPattern("d-M-y");
DateTime dtFrom = formatter.parseDateTime(dateFrom);

The date is grabbed from a jquery datepicker field setup like this:

$( "#from" ).datepicker({
                dateFormat: 'd-M-y',
                defaultDate: null,
                changeMonth: true,
                minDate: 0,
                numberOfMonths: 1,
                onClose: function( selectedDate ) {
                    $( "#to" ).datepicker( "option", "minDate", selectedDate );
                }
            });

The console is outputting this and you can also see the input there too, which i believe is correct

WARNING: StandardWrapperValve[SearchServlet]: PWC1406: Servlet.service() for servlet SearchServlet threw exception
java.lang.IllegalArgumentException: Invalid format: "26-Jan-13" is malformed at "Jan-13"

Upvotes: 0

Views: 2987

Answers (1)

Reimeus
Reimeus

Reputation: 159864

Similar to the SimpleDateFormat class, a single M is used to parse a numeric month value. You can use MMM to parse text-based months:

DateTimeFormat.forPattern("d-MMM-y");

From DateTimeFormat:

Month: 3 or over, use text, otherwise use number.

Upvotes: 3

Related Questions