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.
format(myDate. setDate(myDate. getDate()+5),("dd/mm/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.
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.
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.
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/
Try:
new Date(Date.now() + 1000 /*sec*/ * 60 /*min*/ * 60 /*hour*/ * 24 /*day*/ * 10)
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