JavaScript how to get tomorrows date in format dd-mm-yy

I am trying to get JavaScript to display tomorrows date in format (dd-mm-yyyy)

I have got this script which displays todays date in format (dd-mm-yyyy)

var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")

Displays: 25/2/2012 (todays date of this post)

But how do I get it to display tomorrows date in the same format i.e. 26/2/2012

I tried this:

var day = currentDate.getDate() + 1

However I could keep +1 and go over 31 obviously there are not >32 days in a month

Been searching for hours but seems to be no answer or solution around this?


This should fix it up real nice for you.

If you pass the Date constructor a time it will do the rest of the work.

24 hours 60 minutes 60 seconds 1000 milliseconds

var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")

One thing to keep in mind is that this method will return the date exactly 24 hours from now, which can be inaccurate around daylight savings time.

Phil's answer work's anytime:

var currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 1);

The reason I edited my post is because I myself created a bug which came to light during DST using my old method.


The JavaScript Date class handles this for you

var d = new Date("2012-02-29")
console.log(d)
// Wed Feb 29 2012 11:00:00 GMT+1100 (EST)

d.setDate(d.getDate() + 1)
console.log(d)
// Thu Mar 01 2012 11:00:00 GMT+1100 (EST)

console.log(d.getDate())
// 1

I would use the DateJS library. It can do exactly that.

http://www.datejs.com/

The do the following:

var d = new Date.today().addDays(1).toString("dd-mm-yyyy");

Date.today() - gives you today at midnight.