Is there any difference on JDK5/JDK 6 when converting String to Date

孤街醉人 提交于 2019-12-12 09:00:55

问题


Could it possible that JDK 5 can produce

"default message [Failed to convert property value of type 
'java.lang.String' to required type 'java.util.Date' for property 
'orderDate'; nested exception is  org.springframework.core.convert.ConversionFailedException:Failed to convert
from type java.lang.String to type java.util.Date for value 'Mon May 27 12:27:20 ART 2013'"

But not on JDK6? current application is Spring on JBoss so that the conversion is not explicit. I get this issue from Jboss server on one machine but not from other Jboss on another machine. However right now somehow I can not check the JVM detail with the server has the issue.


回答1:


I doubt JDK Date functions has significant change from version 5 to 6. Maybe it's locale differences between two environments.

Also if you're on Spring MVC it's better practice to define a date string format, and register a property editor for it on your controller, so you can always parse/format regardless of locales, eg:

@InitBinder
public void registerDateBinder(WebDataBinder binder) {
  DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}


来源:https://stackoverflow.com/questions/16802824/is-there-any-difference-on-jdk5-jdk-6-when-converting-string-to-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!