繁体   English   中英

解析时Joda-Time格式无效

[英]Joda-Time Invalid format when parsing

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"

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

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

DateTimeFormat

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM