And*_*ore 111
当然是啦!的Date类有一个被调用的函数getDay()返回0和6之间的整数(0为星期日,6存在星期六).所以,为了看今天是否在周末:
var today = new Date();
if(today.getDay() == 6 || today.getDay() == 0) alert('Weekend!');
Run Code Online (Sandbox Code Playgroud)
要查看任意日期是否为周末,您可以使用以下内容:
var myDate = new Date();
myDate.setFullYear(2009);
myDate.setMonth(7);
myDate.setDate(25);
if(myDate.getDay() == 6 || myDate.getDay() == 0) alert('Weekend!');
Run Code Online (Sandbox Code Playgroud)
小智 27
你可以进一步简化@Andrew Moore的测试:
if(!(myDate.getDay() % 6)) alert('Weekend!');
Run Code Online (Sandbox Code Playgroud)
(喜欢那个模数函数!)
Date类提供getDay()方法,该方法以0到6之间的数字(0 =星期日,1 =星期一等)检索日期的星期几组件.
var date = new Date();
switch(date.getDay()){
case 0: alert("sunday!"); break;
case 6: alert("saturday!"); break;
default: alert("any other week day");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56033 次 |
| 最近记录: |