有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么InitBinder在解析日期时会增加小时数?

我正试图解析从spring表单发送的日期。在我的控制器中,我添加了如下InitBinder:

@InitBinder
public void initBinder( WebDataBinder binder )
{
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
    binder.registerCustomEditor( Date.class, new CustomDateEditor( sdf, true ) );
}

我用Ajax发帖。发送日期为:

registerDateFrom: "2013-09-04"

手动分析此日期时,会给出正确的结果:

sdf.parse( "2013-09-12" )
-----
Wed Sep 04 00:00:00 CEST 2013

使用InitBinder进行解析会使解析日期增加2小时:

Wed Sep 04 02:00:00 CEST 2013

它来自哪里?我曾尝试将时区添加到SimpleDataFormat中,但结果是一样的


共 (0) 个答案