js格式化long型时间戳

225 阅读1分钟

now是后台传来的long型时间戳

formatDate(now) {
let year = now.getFullYear()
let month = (now.getMonth() +1 < 10 ? '0' + (now.getMonth() + 1) : now.getMonth() + 1)
let date = now.getDate() < 10 ? '0' + now.getDate() : now.getDate()
let time = new Date(now)
return year + '-' + month + '-' + date + ' ' + time.toTimeString().substr(0, 8)
},