1.得到本月的几号
let day = new Date().getDate(); //输出15号
2.得到一个月有几天
var curretMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
this.getMouth = curretMonth.getDate(); //输出31天
3.得到几年几月几天:几时几分几秒,格式化,例:2022-07-15 15:04:01
//日期格式化
var time = this.formatDate(new Date())
formatDate(time) {
if (cellValue == null || cellValue == "") return "";
var date = new Date(cellValue)
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()
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}