setUTCFullYear(year)
Sets the year of the UTC date.
The year must be given with four digits (2007 instead of just 07).
UTC time is the same as GMT time.
setUTCFullYear() |
Yes | Yes | Yes | Yes | Yes |
dateObject.setUTCFullYear(year, month, day);
Parameter | Description |
---|---|
year | Required. A four-digit value representing the year, negative values are allowed |
month | Optional. An integer representing the month
Expected values are 0-11, but other values are allowed: |
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed: If the month has 31 days, 32 will be the first day of the next month If the month has 30 days, 32 will be the second day of the next month |
return a number representing milliseconds between the date value and midnight January 1 1970.
var myDate = new Date();
myDate.setUTCFullYear(2012);
console.log(myDate.toString());
The code above generates the following result.
The following code sets the date to UTC November 3, 2010.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w ww .j av a 2s .co m-->
var d = new Date();
d.setUTCFullYear(2010, 10, 3);
document.getElementById("demo").innerHTML = d;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code sets the date to six months ago in UTC time.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- www . j av a 2 s .co m-->
var d = new Date();
d.setUTCFullYear(d.getUTCFullYear(), d.getUTCMonth() - 6);
document.getElementById("demo").innerHTML = d;
}
</script>
</body>
</html>
The code above is rendered as follows: