js时间戳转换日期格式
时间:2021-03-03 12:25:04
收藏:0
阅读:0
let time=1614733234043
let newTime=this.formatDate(time)
formatDate(date) {
let nowdate = new Date(date);
let YY = nowdate.getFullYear() + ‘-‘;
let MM = (nowdate.getMonth() + 1 < 10 ? ‘0‘ + (nowdate.getMonth() + 1) : nowdate.getMonth() + 1) + ‘-‘;
let DD = (nowdate.getDate() < 10 ? ‘0‘ + (nowdate.getDate()) : nowdate.getDate());
let hh = (nowdate.getHours() < 10 ? ‘0‘ + nowdate.getHours() : nowdate.getHours()) + ‘:‘;
let mm = (nowdate.getMinutes() < 10 ? ‘0‘ + nowdate.getMinutes() : nowdate.getMinutes()) + ‘:‘;
let ss = (nowdate.getSeconds() < 10 ? ‘0‘ + nowdate.getSeconds() : nowdate.getSeconds());
return YY + MM + DD +" "+hh + mm + ss;
},
评论(0)