Vue——DatePicker日期选择器进行日期格式化
1、Element 日期选择器控件:<div><el-form:inline="true"class="demo-form-inline"><el-form-itemlabel="Time"required="required">...
·
1、Element 日期选择器控件:
<div>
<el-form
:inline="true"
class="demo-form-inline">
<el-form-item
label="Time"
required="required">
<el-date-picker
v-model="visitDate"
type="datetimerange"
range-separator="To"
start-placeholder="开始日期"
end-placeholder="结束日期"/>
</el-form-item>
</el-form>
</div>
前端显示:
js绑定数据,对应的日期为:this.visitDate[0],this.visitDate[1]
data() {
return {
visitDate: []
}
}
console.log(this.visitDate[0])
打印出来显示:Thu Oct 24 2019 00:00:00 GMT+0800 (中国标准时间)
该值执行数据库时会显示:2019-10-23T16:00:00.000Z,我数据库时间格式为:2019-10-24 00:00:00
2、所以需要将前端传的时间格式化:
formateDate(datetime) {
function addDateZero(num) {
return (num < 10 ? '0' + num : num)
}
const d = new Date(datetime)
const formatdatetime = d.getFullYear() + '-' + addDateZero(d.getMonth() + 1) + '-' + addDateZero(d.getDate()) + ' ' + addDateZero(d.getHours()) + ':' + addDateZero(d.getMinutes()) + ':' + addDateZero(d.getSeconds())
return formatdatetime
}
console.log(this.formateDate(this.visitDate[0]))
重新打印时间:2019-10-24 00:00:00
针对读取数据库时间显示问题解决:https://blog.csdn.net/wx19900503/article/details/100777967
更多推荐
已为社区贡献6条内容
所有评论(0)