JavaScript setUTCMonth

JavaScript setUTCMonth function is a Date Function that is used to set the Month of a specified date as per the universal time. The syntax of the setUTCMonth function is as follows.

 Date.setUTCMonth(Month_Number)

Here, the Month Number should be between 0 and 11. Where 0 = January, and 11 = December.

JavaScript setUTCMonth Example

We use the setUTCMonth function to set the current date month to 5 (June) as per the universal time.

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCMonth(5);
  document.write("After : " + dt);
</script>
</body>
</html>
Example

Date and Time: Thu Nov 08 2018 12:28:57 GMT+0530 (Indian Standard Time)
After : Fri jun 08 2018 12:28:57 GMT+0530 (Indian Standard Time)

In this JavaScript set UTC Month function example, we set the custom date month to 11 (December) according to universal time.

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> JavaScriptsetUTCMonthFunction Example </h1>
<script>
  var dt = Date("May 1, 2016 10:11:19");
  document.write("Date and Time : " + dt + "<br/>");

  dt.setUTCMonth(11);
  document.write("After setUTCMonth() : " + dt);
</script>
</body>
</html>
JavaScript setUTCMonth Example