首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >时间戳MySQL正在减去我约会的两个小时

时间戳MySQL正在减去我约会的两个小时
EN

Stack Overflow用户
提问于 2018-06-27 05:57:37
回答 1查看 40关注 0票数 0

我将信息添加到数据库中,当我想在PreparedStatement (stmt)上设置时间戳(PreparedStatement)时,日期的小时将减少2小时。请参阅代码和输出:

代码语言:javascript
复制
    Connection con = null;
    PreparedStatement stmt = null;
    try {
            con = ds.getConnection();
            stmt = con.prepareStatement("INSERT INTO "+machines.get(0)+ "("+Information.variables.get(0)+","+Information.variables.get(1)+","+Information.variables.get(2)+
                    ","+Information.variables.get(3)+","+Information.variables.get(4)+","+Information.variables.get(5)+","+Information.variables.get(6)+","+Information.variables.get(7)+","+Information.variables.get(8)+
                    ","+Information.variables.get(9)+","+Information.variables.get(10)+","+Information.variables.get(11)+") VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

            String s = info.Data();
            Date d = transformStringToDate(s);
            System.out.println(d);
            java.sql.Timestamp d2 = new java.sql.Timestamp(d.getTime());
            stmt.setTimestamp(1, d2);
            System.out.println(d2);
            
            stmt.setDouble(2, info.Pes_programat());
            stmt.setDouble(3, info.Pes_real());
            stmt.setDouble(4, info.Pes_maxim());
            stmt.setDouble(5, info.Pes_minim());
            stmt.setInt(6, info.Marxa());
            stmt.setDouble(7, info.Incidencia());
            stmt.setDouble(8, info.Contador_de_coixins());
            stmt.setDouble(9, info.Producte());
            stmt.setDouble(10, info.Fibra());
            stmt.setDouble(11, info.Pes_funda());
            stmt.setDouble(12, info.Mides_funda());
            System.out.println(stmt);
            stmt.execute();

    } catch (SQLException e) {
            e.printStackTrace();
    }finally{
            try {
                    if(stmt != null) stmt.close();
                    if(con != null) con.close();
            } catch (SQLException e) {
                    e.printStackTrace();
            }
    }
}

这是System.out.println()的输出:

2018年6月15日(星期五) 18:55:53 2018-06-15 18:55:53.0 com.mysql.cj.jdbc.ClientPreparedStatement:插入m1(数据、Pes_programat、Pes_real、Pes_maxim、Pes_minim、Marxa、Incidencia、Contador_de_coixins、Producte、Fibra、Pes_funda、Mides_funda)值( '2018-06-15 16:55:53.0',211.0、11.98、2.15、1.85、1、0.0、151.0、1.0、2.0、50.0、190.0)

第一个日期类型日期是正确的,并且时间戳d2变量也是正确的。但是当我给stmt.setTimestamp打电话时,它把时间减为2。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-27 06:00:45

CEST比世界协调时提前2小时。这就造成了这种差异。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51055474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档