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

后端 未结 6 1152
忘了有多久
忘了有多久 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:12

    You can simplify @Andrew Moore 's test even further:

    if(!(myDate.getDay() % 6)) alert('Weekend!');
    

    (Love that modulo function!)

提交回复
热议问题