0

Joda-Time 抱怨我的输入格式错误,但我使用的是相同的格式选项:

'd-M-y'

在输入和 Joda-Time 格式化程序中。

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

日期是从 jquery datepicker 字段设置中获取的,如下所示:

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

控制台正在输出这个,你也可以在那里看到输入,我相信这是正确的

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

1 回答 1

3

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.

于 2013-01-26T13:28:56.853 回答