前后端時間格式交互(spring boot + vue.js + element-ui)
GMT/UTC時間格式:yyyy-MM-dd'T'HH:mm:ss.SSSZ
前后端一般的時間交互格式:yyyy-MM-dd HH:mm:ss
前端日期轉化:使用format指定輸入框的格式;使用value-format指定綁定值的格式。
參考自:https://element.eleme.cn/#/zh-CN/component/date-picker#ri-qi-ge-shi
后端接收:注解@JsonFormat主要是后端到前端的時間格式的轉換,注解@DataFormat主要是前端到后端的時間格式的轉換
參考自:https://www.cnblogs.com/mracale/p/9828346.html
element-ui代碼:
<el-form-item label="開始時間" prop="startTime">
????<el-date-pickerv-model="dataForm.startTime" type="datetime"
????????placeholder="選擇日期時間"?
????????value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"
????????:picker-options="pickerOptions">
????</el-date-picker>
</el-form-item>
后端代碼:
1.使用類接受參數
@DateTimeFormat(pattern =?"yyyy-MM-dd")
@JsonFormat(pattern =?"yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private?LocalDateTime startTime;//或者申明為Date對象
2.方法直接接受參數
@GetMapping("/test")
public R test(@DateTimeFormat(pattern="yyyy-MM-dd")
???????????????????? @RequestParam("orderTime") LocalDate orderTime) {
??? return new R();
}