Joda-Time解析时格式无效

时间:2013-01-26 13:18:35

标签: java date datetime datepicker jodatime

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"

1 个答案:

答案 0 :(得分:3)

SimpleDateFormat类相似,使用单个M来解析数字月份值。您可以使用MMM来解析基于文本的月份:

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

来自DateTimeFormat

  

月份:3或以上,使用文字,否则使用数字。

相关问题