js时间戳转换日期格式

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;
},
posted @ 2021-03-03 09:06  白_小白  阅读(225)  评论(0)    收藏  举报