时间转换异常

coder-zm 2017-09-27 08:48:23
log信息如下:
[WARN ] 2017-09-27 07:59:05.539 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException<189> - Resolved exception caused by Handler execution: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'notice' on field 'downlineTime': rejected value [2017-09-27 07:58:53]; codes [typeMismatch.notice.downlineTime,typeMismatch.downlineTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [notice.downlineTime,downlineTime]; arguments []; default message [downlineTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'downlineTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value '2017-09-27 07:58:53'; nested exception is java.lang.IllegalArgumentException]
Field error in object 'notice' on field 'uplineTime': rejected value [2017-09-27 07:58:50]; codes [typeMismatch.notice.uplineTime,typeMismatch.uplineTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [notice.uplineTime,uplineTime]; arguments []; default message [uplineTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'uplineTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value '2017-09-27 07:58:50'; nested exception is java.lang.IllegalArgumentException]
...全文
272 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
annkee058 2017-09-27
  • 打赏
  • 举报
回复
String string = "2014-3-17"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = dateFormat.parse(string);// Mon Mar 17 00:00:00 CST 2014 System.out.println(date.toLocaleString().split(" ")[0]);//2014-3-17 } catch (ParseException e) { e.printStackTrace(); }
coder-zm 2017-09-27
  • 打赏
  • 举报
回复
在jsp传参到controller需要使用@DateTimeFormat( pattern = "yyyy-MM-dd HH:mm:ss" ) 在后端给前端的时候,需要使用@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧