法一:
//获取当前日期的yyyy-MM-dd格式
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return year + "-" + month + "-" + day;
法二:
const date = new Date()
const YYYY = date.getFullYear()
const MM = (date.getMonth() + 1).toString().padStart(2,0)
const DD = date.getDate().toString().padStart(2,0)
return `${YYYY}-${MM}-${DD}`)
法三:
new Date().toISOString().slice(0, 10)
标签:10,const,js,var,日期,date,getMonth,getDate From: https://www.cnblogs.com/maxtong/p/17716424.html