简体   繁体   中英

Add millisecond value to today's date and display Date, And Month and Year (Date, Month and Year are each separate values)

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM