I have a date parameter in DB model and I want to retrive the date in this format "dd/MM/yyyy". I have annotation on getter like below:
@CreationTimestamp
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern = "dd/MM/yyyy")
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
However, I receive date in format yyyy-MM-dd. It seems that the @Temporal annotations formats to 'yyyy-MM-dd' but the DateTimeFormat has no effect.
rest response:
{
"id":"token1497340427913",
"status":"finished",
"startDate":null,
"endDate":null,
"created":"2017-06-13",
"modified":"2017-06-13"
}
You might use @JsonFormat, look the chapter 3.2 http://www.baeldung.com/jackson-jsonformat
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSSZ")
private Date created;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.