js获取年月日 时分秒的日期格式

const date = new Date()
const year = date.getFullYear()
const month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`
const day = date.getDate() >= 10 ? date.getDate() : `0${date.getDate()}`
const hours = date.getHours() >= 10 ? date.getHours() : `0${date.getHours()}`
const min = date.getMinutes() >= 10 ? date.getMinutes() : `0${date.getMinutes()}`
const s = date.getSeconds() >= 10 ? date.getSeconds() : `0${date.getSeconds()}`

const newDate = `${year}-${month}-${day} ${hours}:${min}:${s}`

js获取年月日 时分秒的日期格式,如:2022-05-06 10:00:08

你可能感兴趣的:(时间对象,javascript,elementui,vue.js)