// 获取当前日期
const currentDate = new Date()
// 获取年、月、日
const year = currentDate.getFullYear()
const month = String(currentDate.getMonth() + 1).padStart(2, '0')
const day = String(currentDate.getDate()).padStart(2, '0')
// 格式化为 "yyyy-MM-dd" 格式
const formattedDate = `${year}-${month}-${day}`
console.log(formattedDate,'formattedDate') //yyyy-MM-dd 的数据
const newStr = formattedDate.split('-').reverse().join('-') // 获取类似 dd-MM-yyyy 的数据
JS获取当天时间
于 2024-05-16 18:33:40 首次发布