How to use setUTCMonth in JavaScript
In this article, I will explain use of setUTCMonth() method in JavaScript date object.
JavaScript setUTCmonth() method
-
setUTCMonth() method of date method sets the month according to universal time.
-
setUTCMonth() method can also be used to set the day of the month.
-
In setUTCMonth() method, 0 is represent is janurary, february is 1 and so on.
-
UTC time is the same as GMT time.
Syntax
Date.setUTCMonth(month,day)
|
-
month : month is required parameter. An integer is representing the day of month and it's value between 0 and 11.
-
day : day is optional parameter. A number is representing the day and it's value between 1 and 31.
Example
In the following example show to setUTCMonth() method set the date to be the last day of last month according to UTC.
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Lime ">JavaScript setUTCMonth() Method Example</h3>
<p id="demo">Click for display the date after set the date to be the last day of last month.</p>
<button onclick="myFunction()">Click On</button>
<script type="text/javascript">
function myFunction() {
var d = new Date();
d.setUTCMonth(d.getUTCMonth(), 0);
var x = document.getElementById("demo");
x.innerHTML ="After set the date to be last of month : "+ d;
}
</script>
</body>
</html>
|
Output1
Output2
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here