@JsonFormat後臺到前臺的時間格式的轉換
@DataFormAT前後到後臺的時間格式的轉換
1.@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
pattern:需要轉換的時間日期的格式
timezone:是時間設置爲東八區
2.@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
pattern:需要轉換的時間日期的格式
3.例子
/*倆個註解可以同時使用*/
@ApiModelProperty("創建時間") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createdDate ;
舉例:以下ClinicalTrialSettleParamVO 作爲swagger入參,日期類型的列,可同時接收時間戳和時間類型的數據
若不加任何註解,默認接收時間戳,返回json也是long類型的時間戳
public class ClinicalTrialSettleParamVO {
@Schema(description = "項目id", required = true, example = "LCSY2019091000000001")
private String projectId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss" ,timezone = "GMT+8")
@Schema(description = "起始時間", required = true, example = "2019-11-01 00:00:00")
private Date startTimestamp;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss" ,timezone = "GMT+8")
@Schema(description = "結束時間", required = true, example = "2019-11-01 23:59:59")
private Date endTimestamp;
public ClinicalTrialSettleParamVO() {
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public Date getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(Date startTimestamp) {
this.startTimestamp = startTimestamp;
}
public Date getEndTimestamp() {
return endTimestamp;
}
public void setEndTimestamp(Date endTimestamp) {
this.endTimestamp = endTimestamp;
}
}