【问题标题】:match datetime pattern with spring DatetimeFormat annotation将日期时间模式与 spring DatetimeFormat 注释匹配
【发布时间】:2015-07-18 14:36:34
【问题描述】:

我正在尝试使用这个 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]

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

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

更新原始问题:

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

但我无法获得第二部分 - 所以我将把它重新分配给 jquery-inputmask 标签,因为它分别以 ap 提交 am/pm 的事实可能是一个错误。 ...

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

【问题讨论】:

    标签: spring-mvc jquery-inputmask


    【解决方案1】:

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

    【讨论】:

    • 发布像 050520161234PM 这样的值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多