//将当前时间,转换为年月日形式,调取this.timeStamp()
点击查看代码
timeStamp: function(value) {
var date = new Date(value*1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var year = date.getFullYear();
var month = ("0" + (date.getMonth() + 1)).slice(-2);
var sdate = ("0" + date.getDate()).slice(-2);
var hour = ("0" + date.getHours()).slice(-2);
var minute = ("0" + date.getMinutes()).slice(-2);
var second = ("0" + date.getSeconds()).slice(-2);
// 拼接
var result = year + "年" + month + "月" + sdate + "日 " + hour + "时" + minute + "分" + second + "秒";
// 返回
return result;
},
//系统时间格式转换成自定义格式
点击查看代码
getDate(type) {
// 获取当前系统时间
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
month = month > 9 ? month : '0' + month;;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
},