How to use setUTCFullYear in JavaScript
In this article, I will explain use of setUTCFullYear() method in JavaScript date object.
JavaScript setUTCFullYear() method
-
setUTCFullYear() method of date object sets the full year of a date object for a given date according the universal time.
-
UTC is the set by the World Time Standard.
-
UTC time is the same as GMT time.
Syntax
Date.setUTCFullYear(yearValue,monthValue,dayValue)
|
- yearValue : A four-digit value representation the year. An integer specifying the numeric value of the year, for example, 2012.
- monthValue : monthValue is the optional parameter. An integer between 0 and 11 representing the months January through December.
- dayValue : dayValue is the optional parameter. An integer between 1 and 31 representing the day of the month. If you given the dayValue parameter, you must also given the monthValue.
Example
In the following example show to setUTCFullYear() method set the date to five months ago.
<!DOCTYPE html>
<html>
<body>
<h3 style="color:red ">JavaScript setUTCFullYear() Method Example</h3>
<p id="demo">Click the button to display the date five months ago.</p>
<button onclick="myFunction()">Click</button>
<script type="text/javascript">
function myFunction() {
var d = new Date();
d.setUTCFullYear(d.getUTCFullYear(), d.getUTCMonth() - 5);
var x = document.getElementById("demo");
x.innerHTML ="five months ago date is : "+ 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