获取当前日期
Date date = new Date()
date.toUTCString() // 获取格林尼治的日期+时间(Mon, 15 May 2023 07:10:51 GMT)
date.toLocaleString() // 获取本地日期+时间(2023/5/15 15:10:24)
date.toLocaleDateString() // 获取本地日期(2023/5/15)
date.toLocaleTimeString() // 获取本地时间 (15:11:58)
date.getMilliseconds() // 返回毫秒(0~999)
date.getSeconds() // 返回秒(0~59)
date.getMinutes() // 返回分钟(0~59)
date.getHours() // 返回小时(0~23)
date.getDate() // 返回几号(1~31)
date.getDay() // 返回星期几(0~6),星期天用表示
date.getMonth() // 返回月份(0~11),十二月用0表示
date.getYear() // 获取年份,从1900年开始,比如2022年是122
date.getFullYear() // 获取四位数的年份,此时2022年是2022
date.getTime() // 返回1970年1月1日8时0分0秒至今的毫秒数,
获取指定日期
获取指定月份天数
getNowMonth(dateStr: string) {
let date = new Date(dateStr); // dateStr格式:"2018/10/01"或者"2018-10-01"
date.setMonth(date.getMonth() + 1); // 先设置为下个月
date.setDate(0); // 再置0,变成当前月最后一天
console.log('指定月份天数',date.getDate());
}