/** * 日期格式化,接下来我们就来聊聊关于js怎么转成日期?以下内容大家不妨参考一二希望能帮到您!

js怎么转成日期(js时间转化格式)

js怎么转成日期

/**

* 日期格式化

* @param {时间对象} date

* @param {字符串} str

* @param {布尔值} isTime

* @param {tiemStr} str

*/

function formatDate(date, isTime = false, str = '-', tiemStr = ':'){

date = new Date(date)

let Y = date.getFullYear()

let M = (date.getMonth() 1) < 10 ? '0' (date.getMonth() 1) : date.getMonth() 1

let D = date.getDate() < 10 ? '0' date.getDate() : date.getDate()

if(isTime){

let h = date.getHours() < 10 ? '0' date.getHours() : date.getHours()

let m = date.getMinutes() < 10 ? '0' date.getMinutes() : date.getMinutes()

let s = date.getSeconds() < 10 ? '0' date.getSeconds() : date.getSeconds()

return Y str M str D ' ' h tiemStr m tiemStr s

}

return Y str M str D

}

export { formatDate}

,