<script type="text/javascript">
var mydate=new Date();//定义日期对象
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];//定义数组对象,给每个数组项赋值
var mynum=mydate.getDay();//返回值存储在变量mynum中 document.write(mydate.getDay());//输出getDay()获取值
document.write("今天是:"+ weekday[mynum]);//输出星期几</script>
我感觉我直接这样:
var a=new Date();
var b=a.getDay();
document.write("今天是星期" + b) ;
这样不还方便简单些吗?也可以输出今天的是星期几
你这样不行的,b输出的是0~6的数字,请问有星期0的说法吗?有星期1的说法吗?所以必须用数组
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var mynum=mydate.getDay();
document.write("今天是:"+ weekday[mynum]);