Home > Web Front-end > JS Tutorial > The JavaScript method getUTCMonth() returns a number representing the month (UTC)

The JavaScript method getUTCMonth() returns a number representing the month (UTC)

黄舟
Release: 2017-11-06 13:20:13
Original
1626 people have browsed it

Definition and Usage

The getUTCMonth() method returns a number representing the month (according to Universal Time UTC).

Syntax

dateObject.getUTCMonth()
Copy after login

Return value

Return dateObject The month expressed in universal time, the value is between 0 (January) ~ 11 (December) An integer.

It should be noted that the Date object uses 1 to represent the first day of the month, instead of using 0 to represent the first month of the year like the month field.

Tips and Notes:

Note: This method is always used in conjunction with a Date object.

Tip: For more information about Universal Coordinated Time (UTC), please refer to Baidu Encyclopedia.

Example

Example 1

In this example, we will get the current month and then output it:

<script type="text/javascript">

var d=new Date()

document.write(d.getUTCMonth())

</script>
Copy after login

Output:

10
Copy after login

Example 2

Now, we will create an array so that our example above can output the name of the month instead of 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>
Copy after login

Output:

The month is November
Copy after login

The javascript Date.getUTCMonth() method returns the month on the specified date according to universal time. The value returned by getUTCMonth is an integer between 0 and 11 corresponding to the month. 0 represents January, 1 represents February, 2 represents March, and so on.

Example:

The following example prints the month part of the current time variablehrs.

<html>
<head>
<title>JavaScript getUTCMonth Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date();
  document.write("getUTCMonth() : " + dt.getUTCMonth() ); 
</script>
</body>
</html>
Copy after login

This will produce the following results:

getUTCMonth() : 7
Copy after login


The above is the detailed content of The JavaScript method getUTCMonth() returns a number representing the month (UTC). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template