Hints:
1. The javascript date object has a method
.getTime()
that allows you to get an integer that represents the number of milliseconds since an
arbitrary date*.
2. You can use a number in the same format passed as a parameter when creating/setting a date object.
Note: The
arbitrary date is actually "Thu Jan 01 1970 11:00:00 GMT+1100 (AUS Eastern Daylight Time)" over here. - if you use the value of 0 in a call to .setTime you can see this reflected in the resultant date).
With that in mind, consider the following snippet:
var now = new Date();
var hourLater dayLater = new Date();
hourLater dayLater.setTime( now.getTime() + (24 * 60 * 60 * 1000) );
We simply create two date objects and initialize them with the current time.
Next, we get the current time as the number of ms since 1/1/1970 and finally add the number of milliseconds in 24 hours, before using this value to set the second date object.
Finally, punching now and
hourLater dayLater into the console gives the following:
> now
< Wed Feb 18 2015 01:09:36 GMT+1100 (AUS Eastern Daylight Time)
>
hourLater dayLater
< Thu Feb 19 2015 01:09:36 GMT+1100 (AUS Eastern Daylight Time)
Lastly: Chrome will autosuggest the available members of an object when typing in the console. I.e, if you open it up (Ctrl-Shift-I) and type "var test = new Date();" you'll get a response that says "undefined". If you then type "test.", Chrome will show a drop-down list of available members of the Date object.