vue中 将时间戳转换为yy-mm-dd形式的日期
这段时间一直在忙着赶项目,今天给大家分享一个小应用,在我们平时开发中都会遇见的,话不多说,直接上代码。时间戳代码<van-field class="date-b" v-model="dateValue" placeholder="交付时间" @click="show = !show"/>js部分//。return{dateValue: "2019-5-23", //...
·
这段时间一直在忙着赶项目,今天给大家分享一个小应用,在我们平时开发中都会遇见的,话不多说,直接上代码。
时间戳代码
<van-field class="date-b" v-model="dateValue" placeholder="交付时间" @click="show = !show"/>
js部分//。
return{
dateValue: "2019-5-23", //自定义交付时间
}
formatDate(date, fmt) {
if (!date) return;
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
(date.getFullYear() + "").substr(4 - RegExp.$1.length)
);
}
let o = {
"M+": addZero(date.getMonth() + 1),
"d+": addZero(date.getDate()),
"h+": date.getHours(),
"m+": date.getMinutes(),
"s+": date.getSeconds()
};
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
let str = o[k] + "";
fmt = fmt.replace(RegExp.$1, str);
}
}
function addZero(num) {
return num >= 10 ? num : "0" + num;
}
return fmt;
},
//将时间的值赋值在页面上
Confirm() {
this.newValue = this.formatDate(this.currentDate, "yyyy-MM-dd");
// console.log(newTime);
this.dateValue = this.newValue;
this.show = false;
},
通过我们时间戳的转换,把获取的时间赋值到指定得位置,这样页面就能显示我们要取的
数据了,
更多推荐
已为社区贡献11条内容
所有评论(0)