Determine if a date is a Saturday or a Sunday using JavaScript

后端 未结 6 1162
忘了有多久
忘了有多久 2020-12-08 01:54

Is it possible to determine if a date is a Saturday or Sunday using JavaScript?

Do you have the code for this?

6条回答
  •  一向
    一向 (楼主)
    2020-12-08 02:13

    I think this is an elegant way to do this:

    function showDay(d) {
        return ["weekday", "weekend"][parseInt(d.getDay() / 6)];
    }
    
    console.log(showDay(new Date()));
    

提交回复
热议问题