1

We are using spring boot for our REST application we are facing issue while using date conversion as mention below if we get a date as 2019-03-13 from payload then while converting in to date using jackson2 we get it as 2019-03-12 which is a day before .

we face this issue with our server in US location , but this works for machine in india location .

We fix above using @Jsonformat(pattern="yyyy-MM-dd",timeZone="US/Eastern")

But we are looking for solution which can work for machine located in any timezone

Aniket
  • 11
  • 1
  • 1
    Jackson will treat your date as UTC, and then convert it to timezone US. Since the default hour is `00:00:00`, it will attempt to convert `2019-03-13 00:00:00 UTC` to timezone US, resulting in `2019-03-12 20:00:00`. That's why you get back `2019-03-12` instead of `2012-03-13`. If you need timezone to be preserved you should receive it from frontend. Or save everything as UTC and specify timezone only for displaying purposes – BackSlash Mar 13 '19 at 10:35
  • To provide a good answer, could you please tell us, which type (e.g. `Instant`, `ZonedDateTime`, etc.) you are using for the field which is carrying the annotation mentioned above? – mle Mar 13 '19 at 22:10
  • Take a look on these two similar questions: [Problem with timezone in Json response from Spring](https://stackoverflow.com/questions/55380919/problem-with-timezone-in-json-response-from-spring) and [Spring Boot Jackson date and timestamp Format](https://stackoverflow.com/questions/55256567/spring-boot-jackson-date-and-timestamp-format) – Michał Ziober Mar 30 '19 at 00:50

0 Answers0