日常工作中封装的方法,可以获取指定月最后一天的日期
/* 获取指定月最后一天
* @params time 时分秒 "hh:mm:ss"
* @return stringDate 字符串时间
* $getCurrentDate() => 2021-05-21 13:15:28
* $getCurrentDate(10) => 2021-05-21
* $getCurrentDate(16) => 2021-05-21 13:15
*/
function $getTheDayOfMonth(month,time) {
let date = new Date(),
year = date.getFullYear()
return new Date(year, month, 0).toLocaleDateString().replace(/(\d{4})\/(\d{1,})\/(\d{1,})/, (all, s1, s2, s3) => {
return `${s1}-${('0'+s2).slice(-2)}-${('0'+s3).slice(-2)} `
}).slice(0, 10) + " " + time
}
上一篇:js获取当月最后一天的日期, 2021-05-21 13:15:28 这样的格式
下一篇:怎么给vue自定义组件加上v-model?