I am trying to add a year to todays date. I am working in a system that does not allow you to use standard
JavaScript.
For instance, to get todays date I have to use:
javascript:now();
I have tried:
javascript:now(+1);
I have never seen this before, but am in need of adding one year to todays date...
Has anyone seen getting current date this way before? And if so, how could I add a year?
const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.
You can create a new date object with todays date using the following code:
var d = new Date(); console.log(d);
If you want to create a date a specific time, you can pass the new Date constructor arguments
var d = new Date(2014); console.log(d)
// => Wed Dec 31 1969 16:00:02 GMT-0800 (PST)
If you want to take todays date and add a year, you can first create a date object, access the relevant properties, and then use them to create a new date object
var d = new Date(); var year = d.getFullYear(); var month = d.getMonth(); var day = d.getDate(); var c = new Date(year + 1, month, day); console.log(c);
// => Tue Oct 11 2016 00:00:00 GMT-0700 (PDT)
You can read more about the methods on the date object on MDN
Date Object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With