Jsonformat changing date on a get request

Asked

Viewed 2,523 times

0

I have a java web service using Spring Boot, in a class I have a date attribute and I use Jsonformat to format the date and convert on the client side using Gson. However, even defining the locale for the zone of Brazil, which would be UTC-03, it converts to three hours more, making the date different. How to solve this problem?

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss", locale = "UTC-03")
private Date date;

1 answer

3

However, even defining the locale for the Brazilian zone, which would be UTC-03

Actually, the locale has another meaning.

Try changing the annotation to define the Timezone:

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss", timezone="GMT-3")
private Date date;
  • I had already tried this approach, but it didn’t work. However, this time it did. I have no idea what might have happened..

  • When I put the application in Tomcat, it continues increasing 3 hours, even with the Timezone set.

  • Marcelo, did you solve it? I have the same problem.

  • 1

    Oops... using Timezone solved my problem! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.