Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I would really appreciate some help creating some JavaScript that will eventually be used in Selenium that automatically sets a date 10 days ahead from the current date and displays in the following format dd/mm/yyyy.

I currently have the script below, but I'm not getting anywhere with it :

var myDate=new Date(); myDate.now.format(myDate.setDate(myDate.getDate()+5),("dd/mm/yyyy"); 

Any help would be much appreciated.

like image 596
Julian Avatar asked Aug 26 '10 06:08

Julian


People also ask

How to get future date in java in dd mm yyyy format?

format(myDate. setDate(myDate. getDate()+5),("dd/mm/yyyy");

How do you format a date in mm dd yyyy?

dd/MM/yyyy — Example: 23/06/2013. yyyy/M/d — Example: 2013/6/23. yyyy-MM-dd — Example: 2013-06-23. yyyyMMddTHH:mmzzz — Example: 20130623T13:22-0500.

How to set a future date in js?

Use the new Date() constructor to create a date instance of today. Then, retrieving the day of tomorrow is a calculation of adding one day to the current day of the month using. You can retrieve the day of “today” using the . getDate() method.

What is format mmm dd yyyy?

MMM/DD/YYYY. Three-letter abbreviation of the month, separator, two-digit day, separator, four-digit year (example: JUL/25/2003) YY/DDD. Last two digits of year, separator, three-digit Julian day (example: 99/349) DDD/YY.


2 Answers

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 created alert(targetDate);  var dd = targetDate.getDate(); var mm = targetDate.getMonth() + 1; // 0 is January, so we must add 1 var yyyy = targetDate.getFullYear();  var dateString = dd + "/" + mm + "/" + yyyy;  // So you can see the output alert(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/

like image 192
Fenton Avatar answered Sep 21 '22 08:09

Fenton


Try:

new Date(Date.now() + 1000 /*sec*/ * 60 /*min*/ * 60 /*hour*/ * 24 /*day*/ * 10) 
like image 33
HaNdTriX Avatar answered Sep 22 '22 08:09

HaNdTriX