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
Parameter | Description |
---|---|
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 |
day | Optional. 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
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:
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
- JavaScript: Date setUTCDate() Method
- JavaScript: Date.getUTCDate() Method
- javaScript Digital Clock with date
- JavaScript: Set Date Methods
- String Contains JavaScript | String includes() Method
- JavaScript Get Date Methods
- JavaScript Operators With Examples
- Sorting Using JavaScript Array Sort() Method
- JavaScript Replace String With Examples
- JavaScript Array splice() Method By Example
- JavaScript: Clone an Array & Object By Example
- Check the Object is Array or not in javascript
- JavaScript: Convert String to Array JavaScript
- javaScript Push() Array By Example
- javaScript Push Array, Items Into Array Example
- JavaScript: Important Array Methods
If you have any questions or thoughts to share, use the comment form below to reach us.