Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Set the Year Value of a Date Object</title> </head> <body> <script> var d = new Date(); d.setFullYear(d.getFullYear() + 2); document.write(d); // Display future date </script> </body> </html>