Answer the question
In order to leave comments, you need to log in
How to store date in PostgreSQL database?
Hello. I receive a date in the form of a long number from another program. I need to save this date in the database. So far, I quickly did it to save it as a string, like this:
String dateTime = new Date(event.getCreateTime()).toInstant().toString();
Answer the question
In order to leave comments, you need to log in
Solved this problem. It turned out that it was my jamb: I did not notice, and set the column type to "time with time zone", but it was necessary - "timestamp with time zone". I now perform the conversion of the incoming date like this:
long createTime = event.getCreateTime();
preparedStatement.setTimestamp(column, new java.sql.Timestamp(createTime), Calendar.newInstance());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question