【问题标题】:Joda-Time Invalid format when parsingJoda-Time 解析时格式无效
【发布时间】:2013-01-26 13:18:34
【问题描述】:

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"

【问题讨论】:

    标签: java date datetime datepicker jodatime


    【解决方案1】:

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

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

    来自DateTimeFormat:

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

    【讨论】:

    • 我明白了。感谢您的帮助
    猜你喜欢
    • 2013-08-17
    • 2013-09-20
    • 2015-01-24
    • 2011-06-18
    • 2011-03-19
    • 2021-04-14
    • 2014-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多