Set date 10 days in the future and format to dd/mm/yyyy (e.g. 21/08/2010) Set date 10 days in the future and format to dd/mm/yyyy (e.g. 21/08/2010) javascript javascript

Set date 10 days in the future and format to dd/mm/yyyy (e.g. 21/08/2010)


Here is an example of getting the future date...

var targetDate = new Date();targetDate.setDate(targetDate.getDate() + 10);// So you can see the date we have createdalert(targetDate);var dd = targetDate.getDate();var mm = targetDate.getMonth() + 1; // 0 is January, so we must add 1var yyyy = targetDate.getFullYear();var dateString = dd + "/" + mm + "/" + yyyy;// So you can see the outputalert(dateString);

There are some more graceful ways to format dates, examples can be found at the following destinations:

http://www.west-wind.com/Weblog/posts/282495.aspx

http://www.svendtofte.com/javascript/javascript-date-string-formatting/


Try:

new Date(Date.now() + 1000 /*sec*/ * 60 /*min*/ * 60 /*hour*/ * 24 /*day*/ * 10)


I needed to do something like this, but I needed the result in-line.So this is what worked for me to get the date 10 days from now:

new Date((new Date()).getTime() + (10 * 86400000))