问题
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