js 如何获取某一个月的第一天是周几
calendar ??? padding dates
// day = 1
const firstMonthDate = new Date(year + month + 1);
const weekDays = ['周日','周1','周2','周3','周4','周5','周6'];
const firstMonthDate = weekDays[firstMonthDate.getDay()]
demo
const weekDays = ['周日','周1','周2','周3','周4','周5','周6'];
const day = new Date("4/1/2020").getDay();
const weekDay = weekDays[day];
weekDay;
// "周3"
new Date("4/1/2020").toLocaleDateString();
// "4/1/2020"
new Date("4/1/2020").getDate();
// 1
new Date("4/1/2020").getDay();
// 3
new Date("4/1/2020").getTime();
// 1585670400000
new Date(1585670400000).toLocaleDateString()
// "4/1/2020"
//当前月当天日期对象:
var date=new Date();
//当前月第一天日期对象:
date=new Date(date.setDate(1))
//当前月第一天星期几:
var weekday=date.getDay();
https://segmentfault.com/q/1010000004939369
function getWeekStartAndEnd() {
const oneDayTime = 1000 * 60 * 60 * 24; // 一天里一共的毫秒数
const today = new Date();
const todayDay = today.getDay(); // 获取今天是星期几,假设是周3
const startDate = new Date(
today.getTime() - oneDayTime * (todayDay - 1)
);
const endDate = new Date(today.getTime() + oneDayTime * (7 - todayDay));
return { startDate, endDate };
}
const week = getWeekStartAndEnd();
console.log(week.startDate, week.endDate);
https://www.lagou.com/lgeduarticle/47091.html
《枕边算法书》
康威的末日算法
https://www.jianshu.com/p/5fb65afb16a3