js--时间戳转成要求的日期格式

//时间戳
//时间戳转化成时间格式
timeFormat(timestamp) {
console.log(timestamp)
//timestamp是整数,否则要parseInt转换,不会出现少个0的情况
var time = new Date(timestamp)
var year = time.getFullYear()
var month = time.getMonth() + 1
var date = time.getDate()
var hours = time.getHours()
var minutes = time.getMinutes()
var seconds = time.getSeconds()
let timestr = year + this.add0(month) + this.add0(date)
console.log(timestr, 'timestr')
return timestr
},
add0(m) {
return m < 10 ? '0' + m : m
}
posted @ 2021-01-24 12:09  小白呀白菜  阅读(323)  评论(0编辑  收藏  举报