Get the current date (year month day)


let date = new Date(),
    year = date.getFullYear(), //获取完整的年份(4位)
	month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
	day = date.getDate() // 获取当前日(1-31)
	if (month < 10) month = `0${month}` // 如果月份是个位数,在前面补0
	if (day < 10) day = `0${day}` // 如果日是个位数,在前面补0

	console.log(year+'-'+month+'-'+day) 
    输出结果:2023-04-04

Guess you like

Origin blog.csdn.net/m0_38007556/article/details/129946921