Format conversion problem of el-date-picker date picker in ElementUI

The date selected using the el-date-picker date picker is of type string and is in the format pointed by the arrow

Solution one:

1. Add these two after this component to modify the format

<el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd"></el-date-picker>

2. Add annotations to the back-end entity class

Even if the front-end is of string type, the string is converted to LocalDateTime type through the format matching annotation tool that comes with json

  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime userBirthday;

Solution two:

Download a moment.js with npm

1、

npm install moment --save

2. Register in main.js

import moment from "moment";
//需要汉化
moment.locale('zh-cn');
Vue.prototype.$moment = moment;//赋值使用
let date = new Date(moment(this.userInfo.userBirthday).format('YYYY-MM-DD HH:mm:ss'));

Guess you like

Origin blog.csdn.net/weixin_42200886/article/details/129848977
Recommended