Use jQuery/JS to determine the DAY OF WEEK

后端 未结 6 1130
感动是毒
感动是毒 2020-12-03 07:24

Is there a method using either JavaScript or jQuery to determine what day of the week it is? For instance, if the date a user picks in the box is a Sunday, I can alert them.

6条回答
  •  不思量自难忘°
    2020-12-03 07:43

    send date and you will get position of the same day of that month . i.e. 15/02/2018 is Third Thursday.

     /*return day postion and dayname */
        function weekAndDay(date) {
            var arrayWeek =[];
            var date = new Date(date),
            days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
            prefixes = ['','First', 'Second', 'Third', 'Fourth', 'Fifth'];
            if (date.getDate() % 7 == 0) {
                var prefixes2 = date.getDate() / 7;
            }else{
                var prefixes2 = Math.ceil(date.getDate() / 7);
            }
            arrayWeek.push({
                'dayPos' : prefixes[prefixes2] ,
                'dayName' : days[date.getDay()]
            });
            return arrayWeek;
        }
    

提交回复
热议问题