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

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 getMonth()方法


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

Definition and Usage
定义与用法

The getMonth() method returns the month, as a number.
getMonth()方法可以以数字方式返回月份

Syntax
语法

dateObject.getMonth()


Tips and Notes
提示与注意点

Note: The value returned by getMonth() is a number between 0 and 11. January is 0, February is 1 and so on.
注意:getMonth()所返回的值为0到11的数字,比如一月份为0,二月份为1,等等

Note: This method is always used in conjunction with a Date object.
注意:这个方法得和Date对象结合使用


Example
举例

In this example we get the current month and print it:
在这个举例中我们将获得当前的月份数并显示它:

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

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



Example 2
举例2

Now we will create an array to get our example to write the name of the month, and not just a number:
现在我们建立一个数组来将我们所获取的月份数字变为名称:

<script type="text/javascript">
var d=new Date()
var month=new Array(12)
month[0]="January"
month[1]="February"
month[2]="March"
month[3]="April"
month[4]="May"
month[5]="June"
month[6]="July"
month[7]="August"
month[8]="September"
month[9]="October"
month[10]="November"
month[11]="December"
document.write("The month is " + month[d.getMonth()])
</script>

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



Try-It-Yourself Demos
尝试与演示

getMonth()
How to use getMonth() to get the name of the current month.
怎样使用getMonth()来得到当前的月份名

Display the current date in different formats
How to use getDate(), getMonth(), and getFullYear() to display the current date in different formats.
如何使用getDate(), getMonth(), 和getFullYear()用不同的格式来显示当前的日期

评论 (0) All

登陆 | 还没注册?