// 前置补0
export function fillZero(text, totalLenght) {
let str = Array(totalLenght).join("0") + text
return str.slice(-totalLenght)
}
// 服务器的时间转换成日期
export function getServerDate(time, splitText="-") {
let date = new Date(time * 1000);
let year = date.getFullYear()
let month = fillZero(date.getMonth()+1, 2)
let day = fillZero(date.getDate(), 2)
return [year, month, day].join(splitText)
}
let text = getServerDate(123456789)
console.log("text", text)
// 输出:
// text 1973-11-30
js简单补0策略与格式化时间戳
于 2022-03-08 11:17:01 首次发布