Problems with ZonedDateTime object receiving on back-end

Viewed 352

I've faced the problem of receiving of date from front-end. I send date from front-end in the format "2020-01-03T00:00:00+02:00" to ZonedDateTime object in back-end. But instead of 2020-01-03T00:00Z[UTC], I receive 2020-01-02T22:00Z[UTC] (actualy minus 2 hours).

Question:

Is there any way to make ZonedDateTime lib not to convert to UTC, or not to minus timezone? Maybe any annotation?

Controller and object simple code example

Object that came from front-end:

@DIfferentsLombokAnnotations
public class Filters {
  private ZonedDateTime startDate;

  //Other fields
}

Controller:

@PostMapping("/ggg")
public List<ResponceObject> method(@RequestBody Filters filters) {
  //any code
 }
1 Answers

ZonedDateTime only support UTC or UTC+2 which would explain why you're getting the result you have. One option would be to instead of sending a ZonedDateTime send a LocalDate, and LocalTime, and a ZoneId, and a ZoneOffset, then parsing to a ZonedDateTime on the backend. At the end of the day, a ZonedDateTime is already composed of these components.

Related