日期组件
<form-item label="下次备份日期:" prop="f_nexttime" required> <div style="display: inline-block"> <date-picker v-model="detailData.f_nexttime" placeholder="请选择日期..." split-panels type="date" style="width: 200px"> </date-picker> </div> </form-item>
日期格式化
toDateStr (dateTime,timeflag) { const date = new Date(Date.parse(dateTime)); const year = date.getFullYear(); const month = (date.getMonth() + 1) < 10 ? `0${date.getMonth() + 1}` : (date.getMonth() + 1); const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate(); const hour = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(); const min = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(); const sec = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds(); if(timeflag){ return `${year}-${month}-${day} ${hour}:${min}:${sec}`; } else { return `${year}-${month}-${day}`; } },
调用格式化函数
第二个参数true格式为2020-01-07 08:07:00
第二个参数false格式为2020-01-07
this.detailData.f_nexttime = this.toDateStr(this.detailData.f_nexttime,false);
本文作者为gengboxb,转载请注明。