0

Without setting the @RequestParam to String, what is the best way to ultimately support up to a ZonedDateTime, but not require the request to contain a Time or Zone/Offset?

I would like to enable the request to support formats like '2021-05-10T01:10:00.000Z' and also '2021-05-10'. In the case of just a date, I would like to defined a default time and zone if missing.

Current code looks like this

@RequestParam(required=false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 
        ZonedDateTime startDate, @RequestParam(required=false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime endDate)
steve
  • 1,786
  • 1
  • 15
  • 29
  • Does [this](https://stackoverflow.com/a/67641742/10819573) answer your question? – Arvind Kumar Avinash May 21 '21 at 22:06
  • @ArvindKumarAvinash, kind of, but how would you use it in the RequestParam? – steve May 24 '21 at 19:48
  • Steve - Following [this method](https://www.baeldung.com/spring-date-parameters#convert-date-parameters-at-the-application-level), you will have to do `dateTimeRegistrar.setDateTimeFormatter(dtf)` where `dtf` is the object from my answer . – Arvind Kumar Avinash May 24 '21 at 20:15

0 Answers0