0

このメソッドを使用して、「18/09/13,02:01:51」のような文字列日付を変換すると:

public static Date stringToDateFormat(String dateString) {
    Date date = null;
    try {
        date = new SimpleDateFormat("dd/MM/yy,hh:mm:ss").parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

これを保存してこの日付オブジェクトを SQL Date に変換し、PostgreSQL データベースに保存すると、2013-09-18 00:00:00 の時間が失われます

ここにDB挿入コード」

String query = "INSERT INTO My_Table(my_date) VALUES (?)";

Date date = stringToDateFormat("18/09/13,02:01:51");

preparedStatement = connection.prepareStatement(query);
preparedStatement.setDate(1, new java.sql.Date(date.getTime()));
preparedStatement.executeUpdate();

コーディングの問題ですか、それとも DB の構成ですか?

ありがとう。

4

1 に答える 1