簡體   English   中英

@Temporal 在 Spring Boot 中格式化日期

[英]@Temporal to format date in Spring Boot

我在 DB 模型中有一個日期參數,我想以這種格式“dd/MM/yyyy”檢索日期。 我在 getter 上有如下注釋:

@CreationTimestamp
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern = "dd/MM/yyyy")
public Date getCreated() {
    return created;
}

public void setCreated(Date created) {
    this.created = created;
}

但是,我收到格式為 yyyy-MM-dd 的日期。 似乎@Temporal 注釋格式為'yyyy-MM-dd',但DateTimeFormat 沒有效果。

休息 回復:

{
   "id":"token1497340427913",
   "status":"finished",
   "startDate":null,
   "endDate":null,
   "created":"2017-06-13",
   "modified":"2017-06-13"
}

您可能會使用@JsonFormat,請查看第 3.2 章http://www.baeldung.com/jackson-jsonformat

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSSZ") 
private Date created;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM