当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript getDay()方法
The getDay() method returns a number that represents the day of the week.
getDay()方法可返回星期几。
dateObject.getDay() |
Note: The value returned by getDay() is a number between 0 and 6. Sunday is 0, Monday is 1 and so on.
注意点:getDay()所返回的值是从0到6的。星期天为0,星期一为1,依次类推
Note: This method is always used in conjunction with a Date object.
注意点:这个方法得和Date对象结合使用
In this example we get the current day (as a number) of the week:
在这个举例中我们将获取当前为星期几(数字的形式):
<script type="text/javascript"> var d=new Date() </script> |
The output of the code above will be:
输出结果为:
Now we will create an array to get our example to write a weekday, and not just a number:
现在我们建立一个数组,然后依据数字来显示出文字的星期几:
<script type="text/javascript"> var d=new Date() var weekday=new Array(7) document.write("Today it is " + weekday[d.getDay()]) </script> |
The output of the code above will be:
输出结果为:
|
getDay()
Use getDay() and an array to write a weekday, and not just a number.
使用getDay()和数组来写出星期几而不仅仅是数字