How can I reformat this date time even I'm putting this annotation in my java code :
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date dateFinContrat;
and in my html file :
<td th:text="${#dates.format(row.dateNaissance, 'dd/MM/yyyy')}"></td>
what i want is to remove the hh:mm:ss in my web page. it shows like this :
CodePudding user response:
2050-07-07 00:00:00.0 As you can see , there's a space before that 00:00:00.
2050-07-07
00:00:00.0
So first try to split that string with 'Space'.
CodePudding user response:
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