javaScript: Method Set UTC Month

javaScript: Method Set UTC Month

JavaScript: Date.setUTCMonth() method. In this tutorial, you will learn how to set UTC month in javascript with an example.

JavaScript: Date.setUTCMonth() method

Definition:- Javascript date setUTCMonth() method, which is used to sets the month for the specified date according to universal time. The setUTCMonth method will accept an integer value between 0 and 11.

Note: January is 0, February is 1, and so on.

Syntax

The syntax is date.setUTCMonth method is:

 Date.setUTCMonth(month, day);

Parameters of setUTCMonth() Method

ParameterDescription
month Required. An integer representing the month.

Expected values are 0-11, but other values are allowed:
1. -1 will result in the last month of the previous year
2. 12 will result in the first month of the next year
3. 13 will result in the second month of the next year
dayOptional. An integer representing the day of month.

Expected values are 1-31, but other values are allowed:
1. 0 will result in the last hour of the previous month
2. -1 will result in the hour before the last hour of the previous month

If the month has 31 days:
32 will result in the first day of the next month
If the month has 30 days:
32 will result in the second day of the next month

Example first

Let’s take first example for Set the month 5 (june) using the setUTCMonth javascript mothod:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript date.setUTCMonth Method</title>
</head>
<body>
  <script type = "text/javascript">
     var date = new Date();
     date.setUTCMonth( 5 );
     document.write( "The javascript date.setUTCMonth() : " + date );
  </script>  
</body>
</html>

Result of example first is

JavaScript date.setUTCMonth Method

Example second

Let’s take the second example for Set the month 5 (june) and day of month 15 th using the setUTCMonth javascript method:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript date.setUTCMonth - Set the month to 5 (June) and the day to the 15th</title>
</head>
<body>
  <script type = "text/javascript">
     var date = new Date();
     date.setUTCMonth(5, 15);
     document.write( "Set the month to 5 (June) and the day to the 15th using date.setUTCMonth() : " + date );
  </script>  
</body>
</html>

Result of second example is:

JavaScript date.setUTCMonth – Set the month to 5 (June) and the day to the 15th

Conclusion

In this javascript tutorial, you have learned how to set a month and day of month using setUTCMonth function with example.

You may like

  1. JavaScript: Date setUTCDate() Method
  2. JavaScript: Date.getUTCDate() Method
  3. javaScript Digital Clock with date
  4. JavaScript: Set Date Methods
  5. String Contains JavaScript | String includes() Method
  6. JavaScript Get Date Methods
  7. JavaScript Operators With Examples
  8. Sorting Using JavaScript Array Sort() Method
  9. JavaScript Replace String With Examples
  10. JavaScript Array splice() Method By Example
  11. JavaScript: Clone an Array & Object By Example
  12. Check the Object is Array or not in javascript
  13. JavaScript: Convert String to Array JavaScript
  14. javaScript Push() Array By Example
  15. javaScript Push Array, Items Into Array Example
  16. JavaScript: Important Array Methods

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *