Java – time zone and formatted date for Grails issues
I hope someone can help solve this very annoying situation. I find myself with Grails & date and time zone as my understanding is not complete
To describe this situation, first I am in the UK and the server where the application is located is in the United States (CST)
When users log in to my application, I have a field that contains their time zone, the only purpose of which is to format dates that reliably fit their location
When the application starts, I enforce the default time zone of UTC, and I also use some joda dates elsewhere in the application, so I set joda datetimezone to UTC But I only use joda for fixed dates, which should not be changed when rendering
So I have timezone in bootstrap setDefault(TimeZone.getTimeZone(“UTC”))
The problem now is that for some tables that I want to record during user interaction, there is a date field called "LastModified", and when the record is updated, I just need to set it to a new date ()
I'm using Ajax calls to render data instead of directly displaying its preprocessed fields in the controller in the GSP, and I've created a formatter for formatting
I think it will be perfect, the date will remain UTC, and then as a European / London user TZ I will see that the date format is correct
However, the time I got was 7 hours
So it behaves like it stores the date and time according to its content in the server location, even if I'm in bootstrap Set the default time in groovy
What should I set without resorting to changing the server time itself?
Solution
It seems that setting the default TZ in the boot program is not enough. I have to add it
To Java_ Opts, so far, the date is displayed correctly