Java uses java.util.Date to save timeStamp type fields in postgresql database, and finds that there is no time, minutes and seconds, only year, month and day, which is very strange.
I have tried to convert it to java.sql.Timestamp at the Java level, and then save it to timeStamp in the database, and found that there is still no time.
I hope someone can help me solve this problem and why it caused such a result. I am very curious about this.
Avoid legacy classes
You are using terrible date-time classes that were years ago supplanted by the modern java.time classes defined in JSR 310. Never use either
Dateclass, norTimestamp.Furthermore, apparently your database is storing a date-only. So both
java.util.Dateandjava.sql.Timestampare misfits. Those represent a moment, a specific point on the timeline, not just a date.DATEcolumn?You neglected to tell us the data type of your column. But I would guess that the column is of Postgres type
DATE, given that you claim to be getting only year-month-day without any time-of-day.The
DATEtype in Postgres is akin to theDATEtype specified in the SQL standard.java.time.LocalDateFor a column of a type akin to the SQL standard type
DATE, the matching Java class mapped in JDBC 4.2+ isjava.time.LocalDate.Write.
Retrieve.