根据日期来获取星期几

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'))

//星期四

 

posted @ 2018-12-20 14:24  秀&莹&锐  阅读(304)  评论(0编辑  收藏  举报