JavaScript getDay() 函数
date.getDay() -- 返回date对象中的星期中的天数(0-6)
- day,中文"一天"的意思
- 引用网址:http://www.dreamdu.com/javascript/date.getDay/
getDay函数语法
date.getDay();
getDay函数返回值
- 返回date对象星期中的一天
- 此值为0(周日)-6(周六)之间的一个整数
getDay函数示例
vard=newDate();document.write(d.getDay());
打印数字形式的星期中的日期
document.write("今天是");vard=newDate();switch(d.getDay()){case0:{document.write("星期日");}break;case1:{document.write("星期一");}break;case2:{document.write("星期二");}break;case3:{document.write("星期三");}break;case4:{document.write("星期四");}break;case5:{document.write("星期五");}break;case6:{document.write("星期六");}break;default:{document.write("发生错误");}}
使用switch返回中文的星期几
vardays=newArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六");day=d.getDay();document.write("今天是"+days[day]);
使用JavaScript数组返回中文的星期几