var today = new Date(); var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000)); var yesterday = new Date(today.getTime() - (24 * 60 * 60 * 1000));
The output will be like this
Today is
Tomorrow is
Yesterday is
Tomorrow is
Yesterday is
Lets make a function for it.
function incrementOrDecrementDate(date, dayValue) { return new Date(date.getTime() + (dayValue * 864e5)); }
If you want to increment the date, pass positive value in dayValue. If you want to decrement the date, pass negative value in it. Let's try to get the date 10 days from today and 10 days before today.
var tenDaysFromNow = incrementorDecrementDate(new Date(), 10);
Here is the result
0 comments:
Post a Comment