C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Date setUTCMonth() methodThe JavaScript date setUTCMonth() method is used to set the integer value that represents the month in the specified date on the basis of universal time. The setUTCMonth() method value starts with 0 that represents January. SyntaxThe setUTCMonth() method is represented by the following syntax: dateObj.setUTCMonth(monthValue[, dayValue]) ParametermonthValue - It represents an integer value between 0 and 11 specifying the month. dayValue - It is optional. It represents an integer value between 1 and 31 specifying the day of the month. JavaScript Date setUTCMonth() method exampleHere, we will understand setUTCMonth() method through various examples. Example 1Let's see an example to print current and updated month. <script> var month=new Date(); document.writeln("Current month : "+(month.getUTCMonth()+1)+"<br>"); month.setUTCMonth(8); document.writeln("Updated month : "+(month.getUTCMonth()+1)); </script> Output: Current month : 8 Updated month : 9 Example 2Let's see an example to update the month of the given date. <script> var month=new Date("August 15, 1947 20:22:10"); month.setUTCMonth(10); document.writeln("Updated month : "+(month.getUTCMonth()+1)); </script> Output: 11 Example 3In this example, we will also specify the particular day with the month. <script> var month=new Date("August 15, 1947 20:22:10"); month.setUTCMonth(10,31); document.writeln("Updated month : "+(month.getUTCMonth()+1)); </script> Output: Updated month : 12
Next TopicJavaScript Date
|