I would recommend formatting the date in either the service or the UI. Also try using LocalDate and LocalDateTime class which are latest class from java.utils.
- Annotation Based
If REST service with JSON response, Please use the following to format the date based on the pattern:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
or
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
- Using DateTimeFormatter or SimpleDateFormat Utility Class
SimpleDateFormat Code Snippet:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = formatter.format(date);
DateTimeFormatter Code Snipped:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
formatter.formate(date);
Please reference: @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss") is Not Working