js 如何獲取某一個月的第一天是周幾


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

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 發布文章使用:只允許注冊用戶才可以訪問!

原創文章,版權所有©️xgqfrms, 禁止轉載 🈲️,侵權必究⚠️!



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM