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

JavaScript
JS数学对象参考
JS字符串对象参考
JS函数参考
JS事件参考
Javascript 常用正则表达式
FF和IE下的js兼容性问题
jQuery 简单介绍
jQuery / 核心 / $(expression, [context] ) 函数
jQuery / 核心 / $(html) 函数
如何使用JS来判断浏览器类型(ie、firefox,等等)
Javascript在IE和FireFox中的不同表现
3个js字符编码函数区别
javascript 中的 XMLDOM 对象

JavaScript getUTCMonth()方法


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

Definition and Usage
定义与用法

The getUTCMonth() method returns a number that represents a month according to the Universal Coordinated Time (UTC).
getUTCMonth()方法根据UTC返回能代表月份的数字

Syntax
语法

dateObject.getUTCMonth()


Tips and Notes
提示与注意点

Note: The value returned by getUTCMonth() is a number between 0 and 11. January is 0, February is 1 and so on.
注意点:getUTCMonth()所返回的数字值范围为0到11,一月份为0,二月份为1,依次下去

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

Tip: The Universal Coordinated Time (UTC) is the time set by the World Time Standard.
提示:UTC是由世界时间标准设定的。


Example
举例

In this example we get the current month and print it:
在这个举例中我们得到当前的月份并输出它:

<script type="text/javascript">
var d=new Date()
document.write(d.getUTCMonth())
</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.getUTCMonth()])
</script>

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



Try-It-Yourself Demos
尝试与演示

getUTCMonth()
How to use getUTCMonth() to get the name of the current month.
getUTCMonth()可用来获取当前月份的名称

Display the UTC date in different formats
How to use getUTCDate(), getUTCMonth(), and getUTCFullYear() to display the UTC date in different formats.
怎样使用getUTCDate(), getUTCMonth(), 和getUTCFullYear()以不同的格式来显示UTC日期

评论 (0) All

登陆 | 还没注册?