上代码!
function getDateTimeToString() {
const date_ = new Date() //获取当前时间
const year = date_.getFullYear() //年
let month = date_.getMonth() + 1 //月
let day = date_.getDate() //日
if (month < 10) month = '0' + month
if (day < 10) day = '0' + day
let hours = date_.getHours() //时
let mins = date_.getMinutes() //分
let secs = date_.getSeconds() //秒
const msecs = date_.getMilliseconds() 毫秒
if (hours < 10) hours = '0' + hours
if (mins < 10) mins = '0' + mins
if (secs < 10) secs = '0' + secs
if (msecs < 10) secs = '0' + msecs
return year + '' + month + '' + day + '' + hours + '' + mins + '' + secs //20230811085628
}