java.util.Date::toString
tells a lie
The Date
class represents a moment in UTC, having an offset of zero hours-minutes-seconds.
The toString
method unfortunately applies the JVM’s current default time zone while generating the text. This creates the illusion of that zone being a part of that object.
Never use java.util.Date
.
ISO 8601
Educate the publisher of your input data about the date-time formats defined in the ISO 8601 standard. These formats are designed for data exchange, easy to parse by machine, and easy to read by humans across cultures.
Database
Your particular input lacks a time zone or offset-from-UTC. So it should be stored in a column of a type akin to the standard SQL type of TIMESTAMP WITHOUT TIME ZONE
(notice WITHOUT, not WITH). Postgres offers that type by that name.
Use a JDBC driver that complies with JDBC 4.2 or later. That standard requires support for exchanging date-time values using the modern java.time classes.
Parse input as shown in your Question.
String input = "05-01-2020 03:07";
String pattern = "dd-MM-yyyy HH:mm";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( pattern ) ;
LocalDateTime ldt = LocalDateTime.parse( input , formatter ) ;
Save to the database.
myPreparedStatement.setObject( … , ldt ) ;
Retrieve.
LocalDateTime ldt = myResultSet.getObject( … , LocalDateTime.class ) ;