How to get the day from a particular date using JavaScript

前端 未结 3 645
情歌与酒
情歌与酒 2020-12-07 01:29

I am new to JavaScript. My requirement is that T want to pop up a message on particular days (like Sunday, Monday...) all through when a date is selected.

I tried

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 02:07

    var date = new Date();
    var day = date.getDay();
    

    day now holds a number from zero to six; zero is Sunday, one is Monday, and so on.

    So all that remains is to translate that number into the English (or whatever other language) string for the day name:

    var name = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day];
    

提交回复
热议问题