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

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+

More on JavaScript Date & Time

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer