Reputation: 27
I am trying to create a testing script in Selenium and I need to enter a date. I have figured out how to get the dates using:
storeEval var d=new Date(); d.getDate() CurrentDay
store Eval var m=new Date(); (m.getMonth()+1) CurrentMonth
storeEval var y=new Date(); y.getFullYear() CurrentYear
Now I want want to create variables for times in the past and future. I have been told I can do so using milliseconds, which is amazing but the closest I can come is this:
storeEval new Date().getTime()+604800000 //604800000- being 7 days in the future
I get back: 1350932638018 which is 7 days forward according to this amazing calculator I found.
So, how do I take the number I found and extract the date, month and year as I did for today's date.
Upvotes: 1
Views: 630
Reputation: 1339
If your future date is stored in the variable d
then it should be as easy as:
var n = new Date(d);
or if it isn't stored in a variable, then maybe something like this?
var n = new Date(Date().getTime()+604800000);
And then now n
is a date object and you should be able to use the .getFullYear()
methods.
Take a look at this fiddle and see if it helps: http://jsfiddle.net/wVVmw/
Upvotes: 2
Reputation: 81
use toDateString()
So,
var newDate = (Date().getTime()+604800000).toDateString();
should return Mon Oct 22 2012
I don't know selenium, but it looks like JavaScript.
Upvotes: 1