programming-examples/js/Date/Write a JavaScript function to add specified years to a date..js

10 lines
254 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function add_years(dt,n)
{
return new Date(dt.setFullYear(dt.getFullYear() + n));
}
dt = new Date();
console.log(add_years(dt, 10).toString());
dt = new Date(2014,10,2);
console.log(add_years(dt, 10).toString());