当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript getUTCMonth()方法
The getUTCMonth() method returns a number that represents a month according to the Universal Coordinated Time (UTC).
getUTCMonth()方法根据UTC返回能代表月份的数字
dateObject.getUTCMonth() |
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是由世界时间标准设定的。
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:
输出结果为:
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) document.write("The month is " + month[d.getUTCMonth()]) </script> |
The output of the code above will be:
输出结果为:
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日期