时间都有那些,有年 月 日 时 分 秒
let date = new Date()
let year = date.getFullYear()
let month = date.getMonth() + 1 >= 10 ? date.getMonth() : `0${(date.getMonth() + 1)}`
let day = date.getDate() >= 10 ? date.getDate() : `0${date.getDate()}`
let hh = date.getHours() >= 10 ? date.getHours() : `0${date.getHours()}`
let mm = date.getMinutes() >= 10 ? date.getMinutes() : `0${date.getMinutes()}`
let ss = date.getSeconds() >= 10 ? date.getSeconds() : `0${date.getSeconds()}`
let time = year + month + day + hh + mm + ss
console.log(time) // 20190215180840
时间戳是将毫秒转换成 天–时--分–秒(DD:HH:MM:SS)
function toDDHHMMSS(data) {
let aLLTime
let day = parseInt((data / 1000 / 60 / 60 / 24))
let hours = parseInt((data % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
let minutes = parseInt((data % (1000 * 60 * 60)) / (1000 * 60))
let seconds = (data % (1000 * 60)) / 1000
let Day = day < 10 ? `0${day}` : day
let Hours = hours < 10 ? `0${hours}` : hours
let Minutes = minutes < 10 ? `0${minutes}` : minutes
let Seconds = seconds < 10 ? `0${seconds}` : seconds
if (day > 0) {
aLLTime = `${Day}:${Hours}:${Minutes}:${Seconds}`
} else {
aLLTime = `${Hours}:${Minutes}:${Seconds}`
}
return aLLTime;
}
let res = toDDHHMMSS(129600000) // 129600000毫秒 === 1.5天 155520000毫秒 === 1.8天
console.log(res) // 01:12:00:00