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 YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    Post your comments , suggestion , error , requirements etc here .




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer