How to get the day of the week from the day number in JavaScript?

后端 未结 8 1113
野的像风
野的像风 2020-12-03 07:05

Given dayNumber is from 0 - 6 representing Monday - Sunday respectively.

Can the Date /

相关标签:
8条回答
  • 2020-12-03 07:34

    let weekday = ['Sunday',
                   'Monday',
                   'Tuesday',
                   'Wednesday',
                   'Thursday',
                   'Friday',
                   'Saturday'][new Date().getDay()];
    
    console.log(weekday)

    0 讨论(0)
  • 2020-12-03 07:36

    This will add a getDayOfWeek() function as a prototype to the JavaScript Date class.

    Date.prototype.getDayOfWeek = function(){   
        return ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][ this.getDay() ];
    };
    
    0 讨论(0)
提交回复
热议问题