将String转换为Date时,JDK5 / JDK 6有什么不同 [英] Is there any difference on JDK5/JDK 6 when converting String to Date
问题描述
JDK 5是否可以生成
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'"
但不是JDK6?目前的应用是Spring在JBoss上,所以转换不明确。我从一台机器上的Jboss服务器上得到这个问题,但不是从另一台机器上的其他Jboss得到这个问题。但是现在不知何故,我无法检查服务器的JVM细节问题。
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.
推荐答案
我怀疑JDK Date函数有显着性从版本5更改为6.也许这是两个环境之间的区域设置差异。
I doubt JDK Date functions has significant change from version 5 to 6. Maybe it's locale differences between two environments.
另外,如果您使用的是Spring MVC,则更好的做法是定义日期字符串格式,并注册一个属性编辑器在你的控制器,所以你可以随时解析/格式,无论区域设置,例如:
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));
}
这篇关于将String转换为Date时,JDK5 / JDK 6有什么不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!