1. 程式人生 > >根據日期來獲取星期幾

根據日期來獲取星期幾

function getWeek(timedat) {  //timedat引數格式: 時間戳
    let week;
    if (timedat.getDay() == 0) week = "星期日";
    if (timedat.getDay() == 1) week = "星期一";
    if (timedat.getDay() == 2) week = "星期二";
    if (timedat.getDay() == 3) week = "星期三";
    if (timedat.getDay() == 4) week = "星期四";
    if (timedat.getDay() == 5) week = "星期五";
    
if (timedat.getDay() == 6) week = "星期六"; return week; } getWeek(new Date('2018-12-20')) //星期四