How to set timezone in quarkus to UTC

I am using quarkus 1.2.0.

General:

The client browser is asking for data from the server. Server (Quarkus app) is receiving the time in utc from the client. (ok) Now the server should compare the data from the database with the clients browser-time and should return every data from the database, which is after the clients-time.

I have postgres as database. Every time when I save new data or modifie data into the database I save the data with the UTC time. I enforce this with <property name="hibernate.jdbc.time_zone" value="UTC"/> in the persistence.xml. I have checked this, the data is save in utc time in the postgres database.

The problem:

Although the data is save in utc in the database, when quarkus fetches the data from the database, it transfers the data to the local timezone (GMT +0100). Now I have the problem that the server is comparing the data converted to (GMT) with the clients time (UTC).

How can I force quarkus to use UTC timezone?


Solution 1:

Have you tried to pass -Duser.timezone=UTC when executing your jar?

A Quarkus app is just a standard Java app.

Another option would be to set it up in your application directly by creating a CDI bean observing the startup event:

@Singleton
public class TimezoneSettings {

    public void setTimezone(@Observes StartupEvent startupEvent) {
        System.setProperty("user.timezone", "UTC");
    }
}

I'm just not entirely sure it will be early enough for your application though. You will have to try it.