function GetDateTime() {
var dateNew = new Date();
var mydate = dateNew.toLocaleDateString(); //获取当天时间
var getDate = dateNew.getDate();//获取当前日
var getYear = dateNew.getFullYear();//获取当前年份
var getMonth = parseInt(dateNew.getMonth() + 1);//获取月份 1月返回0 故在原有基础上+1
var Newdate = new Date(getYear, getMonth, 0)
var daycount = Newdate.getDate();//获取当月天数
var k = 1
var data = []
for (i = getDate; i < daycount + 1; i++) {
var dateDay = new Date(getYear + '/' + getMonth + '/' + i);
var weekDay = dateDay.getDay();//获取当期星期数
if (weekDay != 6 && weekDay != 0) {
data.push({date: "" + getYear + "-" + getMonth + "-" + i + ""})
}
if (i == daycount) {//表示循环了一个月
if (k < 4) {
getMonth = parseInt(dateNew.getMonth() + 1 + k);//获取月份 1月返回0 故在原有基础上+1
Newdate = new Date(getYear, getMonth, 0)
daycount = Newdate.getDate();//获取当月天数
getDate = 1;
k = k + 1
i = 0;
}
}
}
return data
};
JS 获取当前日期三个月的日期,去除周末
最新推荐文章于 2022-09-26 10:58:31 发布