I'm using Java and JDBC connect to a PostgreSQL database. I have a problem saving time to the database. My database have table student with column look like
Id,Name,Created_at(timestamp)
//some row here
I using JDBC connect to PostgreSQL and save my data
jdbc:postgresql://localhost:3306/someDatabase?useSSL=false&serverTimezone=UTC
When I insert data my data looks like
Student student = new Student()
student.name = "some name";
student.createdAt = LocalDateTime.now()
//some logic save
However, when I insert into the database, PostgreSQL saves the same time as my server. I want if my time server is "2021-10-10 00:00:00", when I save to database it must save to database as "2021-10-09 15:00:00". I want when it save it must convert to timezone Japan.
When I select database, timezone on PostgreSQL +9 . If I change code some like:
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
it does not help me.