getDate()
gets the day of the month. If you are passing a number to the Date constructor in new Date(value)
, it expects that number to be the number of milliseconds since the Unix epoch, see Date on MDN. So you're adding 31ms (today) to the unix epoch, hence the date is 01 Jan 1970 and a little bit.
To add one day try:
var secondDate = new Date(testDate.getTime() + 24 * 60 * 60 * 1000);
This adds the milliseconds in one day to testDate
and creates a new Date from it.
getTime()
gets the representation of a date in milliseconds since the Unix epoch, so by adding the number of ms in one day to it, you can create a new Date that is +1 day.