Grails issue with clock and format dates

Hoping someone can help clarify this very unpleasant situation, I am with the Grail and Dates and time zones, as my understanding is not entirely complete.

To describe the situation, firstly, I am in the UK, the server on which the application is installed is located in the USA (CST)

Users connect to my application, and I have a field that stores their time zone for the sole purpose of formatting dates that reliably match their location.

When the application starts, I use the default time zone for UTC, and I also use some Joda Dates elsewhere in the application, so I set Joda DateTimeZone also in UTC. But I only use Joda for fixed dates, which should never change when they are presented.

So in Bootstrap, I have TimeZone.setDefault (TimeZone.getTimeZone ("UTC"))

Now, for this problem for certain tables, I want to record when the user interacts, so I have a Date field called lastModified, and when the record is updated, I just set it to the new Date ()

I use ajax calls to represent data, instead of showing the field directly in GSP, it is pre-processed in the controller, and for formatting I create a formatter with

DateTimeZone dtz = DateTimeZone.forID(user.timeZone) def DateTimeFormatter tzAwareLongFormatter = DateTimeFormat.forPattern('MM/dd/yyyy HH:mm').withZone(dtz); 

I thought it would be perfect and the dates would go UTC, and then, as a user with Europe / London tz, I will see that the dates are formatted correctly.

However, the time I get is +7 hours

So, it acts as if it stores the date and time according to what would be on the Location server, although I set the default time in Bootstrap.groovy.

Is there anything I need to install without resorting to changing the server time itself?

+4
source share
1 answer

It seemed that installing TZ by default in bootstrap was not enough, I had to add

 -Duser.timezone=UTC 

in JAVA_OPTS while the correct dates are displayed.

+1
source

Source: https://habr.com/ru/post/1391512/


All Articles