/**
* 时间戳转换成日期格式
* 调用:timestampToTime(1680498539)
*/
//日期补0
const getzf = (num: number): string | number => {
const numShow: string | number = num < 10 ? `0${num} ` : num
return numShow
}
export const timestampToTime = (timestamp: number): string => {
if (timestamp) {
return ''
}
// 时间戳为10位需*1000,时间戳为13位不需乘1000
const date = timestamp.toString.length === 10 ? new Date(timestamp * 1000) : new Date(timestamp)
const Y = `${date.getFullYear()}-`
const M = `${getzf(date.getMonth() + 1)}-`
const D = `${getzf(date.getDate())}' '`
const h = `${date.getHours()}:`
const m = `${date.getMinutes()}:`
const s = date.getSeconds()
return Y + M + D + h + m + s
}
vue3+ts 时间戳转日期格式
最新推荐文章于 2024-04-29 21:35:15 发布