SQL PHP HTML ASP JavaScript articles and free scripts to download
 

setFullYear()

We can set or fix the year part of the data and time object by using setFullYear() function in JavaScript. This function will change the year part only.

setFullYear(x);

x is four digit year. Let us try one example.

<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
dt.setFullYear(2015);
document.write(dt);
</script>

Output is here

Setting the year part from present year

We can set the year part by reading the present year using getYear function and then use set year part to set the year to a different value. Here is one example

<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
var new_year=dt.getFullYear() + 10
dt.setFullYear(new_year);
document.write(dt);
</script>

Output is here




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Date & Time