Метка времени MySQL вычитает два часа моего свидания

0

Я добавляю информацию в базу данных, и когда я хочу установить отметку времени (d2) на PreparedStatement (stmt), час даты уменьшается на 2 часа. См. Код и вывод:

    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():

Пт Июн 15 18:55:53 CEST 2018

2018-06-15 18: 55: 53,0

com.mysql.cj.jdbc.ClientPreparedStatement: INSERT INTO m1 (данные, Pes_programat, Pes_real, Pes_maxim, Pes_minim, Marxa, Incidencia, Contador_de_coixins, Producte, Fibra, Pes_funda, Mides_funda) VALUES ('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)

Правильно указан тип даты даты Date, а также переменная timestamp d2. Но когда я вызываю stmt.setTimestamp, он помещает часовой декремент на 2.

Теги:
timestamp
date

1 ответ

3
Лучший ответ

CEST - на 2 часа больше, чем в UTC. Это вызывает разницу.

  • 0
    О, это правда. Спасибо

Ещё вопросы

Сообщество Overcoder
Наверх
Меню