I am keeping date_created in TIMESTAMPTZ
date_created TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
in java
@CreatedDate
@Column(nullable = false, updatable = false)
private OffsetDateTime dateCreated;
Also in main application
public class Application {
public static void main(final String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Moscow"));
log.info("Default time-zone: {}", TimeZone.getDefault());
SpringApplication.run(Application.class, args);
}
}
But when I get user.getDateCreated() I get it in UTC+0 format. How should I control my Spring application to automatically receive DateCreated in UTC+3?
I am keeping date_created in TIMESTAMPTZ
date_created TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
in java
@CreatedDate
@Column(nullable = false, updatable = false)
private OffsetDateTime dateCreated;
Also in main application
public class Application {
public static void main(final String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Moscow"));
log.info("Default time-zone: {}", TimeZone.getDefault());
SpringApplication.run(Application.class, args);
}
}
But when I get user.getDateCreated() I get it in UTC+0 format. How should I control my Spring application to automatically receive DateCreated in UTC+3?
Share Improve this question edited Feb 11 at 13:39 Laurenz Albe 250k21 gold badges298 silver badges373 bronze badges asked Feb 11 at 11:12 ЛейлаЛейла 112 bronze badges 1- 2 The title of your question is a bit silly. It is working fine, so asking why it doesn't work doesn't make a lot of sense. Be open to the possibility that the problem is behind the keyboard. – Laurenz Albe Commented Feb 11 at 13:40
2 Answers
Reset to default 0For that, you need to set the session time zone to UTC-03
. Execute this SQL statement after connecting to the database:
SET timezone = 'UTC-03'
There seems to be no connection option to set the parameter during login.
Okay, the problem was in hibernate, not in postgres. In Hibernate 6 hibernate.timezone.default_storage now defaults to DEFAULT, meaning:
if the database/dialect supports it, time zones of date/time values are stored by using the timestamp with time zone SQL column type;
otherwise, time zones of date/time values are not stored, and date/time values are normalized to UTC.
In Hibernate ORM 5, time zones were not stored, but normalized to the time zone set in hibernate.jdbc.time_zone, the JVM time zone by default.
To revert to Hibernate ORM 5’s behavior, set the configuration property hibernate.timezone.default_storage to NORMALIZE.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745215804a4617013.html
评论列表(0条)