使用spring DatetimeFormat注释匹配datetime模式



我正在尝试使用这个jquery输入掩码插件来提交日期时间字段。

输入被提交为:

081220151530 -这是2015年8月12日下午3:30

或在上午/下午提交081220150330p

我正试图将该值绑定到Joda DateTime字段,我认为我应该能够在字段注释上指定自定义模式。

但是这个模式不匹配并且抛出验证错误:

@org.springframework.format.annotation.DateTimeFormat(pattern = "DDMMYYYYhhmm")
private DateTime followUp;

错误:

Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'followUp'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.persistence.Basic @org.hibernate.annotations.Type @org.springframework.format.annotation.DateTimeFormat org.joda.time.DateTime for value '081220151230'; nested exception is org.joda.time.IllegalFieldValueException: Cannot parse "081220151230": Value 22 for monthOfYear must be in the range [1,12]

所以有两个问题:1. 理想情况下,它可以解析am/pm值,那么是否存在与am/pm样式匹配的模式?

  • 如果不是,那么匹配24小时版本的正确模式字符串是什么?

  • 对原问题的更新:

    所以我想出了24H模式,使用DateFormat模式ddMMyyyyHHmm

    但是第二部分我不能得到所以我要把它重新分配给jquery-inputmask标签因为它将am/pm分别作为ap提交可能是一个bug....

    所以我想我可以解决这个问题,如果有人知道如何使它提交pm/am代替?

    尝试:ddmmyyyyhmma发布像05052016这样的值

    最新更新