How to retain ISO 8601 date format in RequestParams when using SPRING BOOT

Viewed 1915

I have the following method which accepts two date parameters in ISO 8601 format. However, when I print these dates I am losing the seconds, milliseconds and the timezone 'Z'. How do I retain the entire date even if the seconds and milliseconds are 0?

            @RequestMapping(method=RequestMethod.GET, value="/status")
                public StatusObject getStatus(@RequestParam("id") String id, 
                                                     @RequestParam("startTime")@DateTimeFormat(iso=DateTimeFormat.ISO.DATE_TIME) LocalDateTime startTime,
                                                     @RequestParam("endTime")@DateTimeFormat(iso=DateTimeFormat.ISO.DATE_TIME) LocalDateTime endTime) throws Exception{

                    StatusObject statusObject = null;

                    System.out.println("startTime: "+ startTime);
                    System.out.println("endTime: "+ endTime);

                    return statusObject;

            }

Input : http://localhost:8080/status?id=123&startTime=2018-05-03T15:00:00.000Z&endTime=2018-05-03T18:00:00.000Z

Output: startTime: 2018-05-03T15:00 endTime: 2018-05-03T18:00

2 Answers

In your case, if you use parameters containing seconds=0 and milliseconds=0 (HH:mm:00.000), LocalDateTime will only output as HH:mm

If you want to save TimeZone values, you should use ZonedDateTime, LocalDateTime does not support this.

Related