当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript getDay()方法

JavaScript
JS 字符串
JS Date
JS数组,JS Array
JS Boolean
JS Math
JS HTML DOM
JS Browser
JS Cookies
JS 校验
JS Animation
JS Image Maps
JS Timing
JS 建立对象
JS 摘要
JS 实例
JS 对象实例
JS DOM 实例
JS数组对象参考
JS布尔对象参考
JS日期对象参考

JavaScript getDay()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 437 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

The getDay() method returns a number that represents the day of the week.
getDay()方法可返回星期几。

Syntax
语法

dateObject.getDay()


Tips and Notes
提示与注意点

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对象结合使用


Example
举例

In this example we get the current day (as a number) of the week:
在这个举例中我们将获取当前为星期几(数字的形式):

<script type="text/javascript">
var d=new Date()
document.write(d.getDay())
</script>

The output of the code above will be:
输出结果为:



Example 2
举例2

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)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"
document.write("Today it is " + weekday[d.getDay()])
</script>

The output of the code above will be:
输出结果为:




Try-It-Yourself Demos
尝试与演示

getDay()
Use getDay() and an array to write a weekday, and not just a number.
使用getDay()和数组来写出星期几而不仅仅是数字

评论 (0) All

登陆 | 还没注册?