获取时间戳
Date.parse()
nDate.valueOf()
nDate.getTime()
Number(nDate)
备注:一天的时间戳:86400000
时间戳转日期
// 转换日期格式
changTime (dateIn) {
const day = Math.floor(dateIn / (1000 * 60 * 60 * 24))
const hours = Math.floor((dateIn / (1000 * 60 * 60)) % 24)
const minutes = Math.floor((dateIn / 1000 / 60) % 60)
const seconds = Math.floor((dateIn / 1000) % 60)
const info = {
d: day < 10 ? '0' + day : day,
h: hours < 10 ? '0' + hours : hours,
min: minutes < 10 ? '0' + minutes : minutes,
s: seconds < 10 ? '0' + seconds : seconds,
}
return info
},
// 转换日期格式
showDate (dateIn) {
let diff = new Date(dateIn)
let y = diff.getFullYear(),
let m = diff.getMonth() + 1,
let d = diff.getDate(),
let h = diff.getHours(),
let min = diff.getMinutes()
let s = diff.getSeconds()
let info = {
y: y,
m: m,
d: d,
h: h,
min: min < 10 ? '0' + min : min,
s: s < 10 ? '0' + s : s
}
return info
}
网友评论