首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用spring DatetimeFormat注释匹配日期时间模式

使用spring DatetimeFormat注释匹配日期时间模式
EN

Stack Overflow用户
提问于 2015-07-18 14:36:34
回答 1查看 908关注 0票数 0

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

所提交的资料如下:

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

或者在上午/下午提交081220150330p

我正在尝试将该值绑定到Joda DateTime字段,并且我认为我应该能够在字段注释中指定一个自定义模式。

但是这个模式不匹配并引发验证错误:

代码语言:javascript
复制
@org.springframework.format.annotation.DateTimeFormat(pattern = "DDMMYYYYhhmm")
private DateTime followUp;

错误:

代码语言:javascript
复制
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样式相匹配?

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

更新为原始问题:

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

但是第二部分我无法理解,所以我要将它重新分配到jquery-inputmask标记中,因为它将am/pm分别作为ap提交,这可能是一个bug……

所以我想如果有人知道如何提交下午/上午时间,我可以解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2016-05-05 04:57:46

尝试: ddMMyyyyHHmma发布类似于05052016的值

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31492230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档