Home > Mobile >  Difference of time between server and database in Grails 4.0.3
Difference of time between server and database in Grails 4.0.3

Time:08-19

I developed a Grails 4.0.3 Rest API to send notifications the to users of a system.

When I save a message in the database, I don't know why but it adds three hours from the current Date. First of all I thought that it was the hour of te server, but when I saw it, I noticed the hour of the server is correct.

Now in Brazil the time is 2022-08-16 12:08:54.710 and the server is correct. But in the database, it saves 2022-08-16 14:55:54.710.

The code below saves a message:

def message = new Message(userId: springSecurityService?.principal?.id,
                                        author: jsonObject.get('author'),
                                        partId: params.partId,
                                        title: jsonObject.get('title'),
                                        text: jsonObject.get('text'),
                                        createdOn: new Date()).save(flush: true, failOnError: true)

Could anyone help me with this problem?

Thanks.

CodePudding user response:

I resolved the problem this way in BootStrap.groovy

System.setProperty("user.timezone", "GMT-03")
TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo"))
  • Related