时间日期处理 2021-03-19 前端 PV: js对时间戳处理成年月日时分秒 + yyyy.mm.dd12345678910111213export function timeToDate(time, type = 'yyyy.mm.dd') { let date = new Date(time) let day = date.getDate() if ((day + '').length < 2) { day = '0' + day } if (type === 'yyyy.mm.dd'){ return `${date.getFullYear()}.${date.getMonth() + 1}.${day}` } else if (type === 'yyyy.mm.dd hh:mm') { let minutes = (date.getMinutes() + '').length <= 1 ? ('0' + date.getMinutes()) : date.getMinutes() return `${date.getFullYear()}.${date.getMonth() + 1}.${day} ${date.getHours()}:${minutes}` }}