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

Method Date.prototype.setDate() accepts even arguments outside the standard range and changes the date accordingly.

function getTomorrow() {
    const tomorrow = new Date();
    tomorrow.setDate(tomorrow.getDate() + 1); // even 32 is acceptable
    return `${tomorrow.getFullYear()}/${tomorrow.getMonth() + 1}/${tomorrow.getDate()}`;
}

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.


Using JS only(Pure js)

Today

new Date()
//Tue Oct 06 2020 12:34:29 GMT+0530 (India Standard Time)
new Date(new Date().setHours(0, 0, 0, 0))
//Tue Oct 06 2020 00:00:00 GMT+0530 (India Standard Time)
new Date(new Date().setHours(0, 0, 0,0)).toLocaleDateString('fr-CA')
//"2020-10-06"

Tomorrow

new Date(+new Date() + 86400000);
//Wed Oct 07 2020 12:44:02 GMT+0530 (India Standard Time)
new Date(+new Date().setHours(0, 0, 0, 0) + 86400000);
//Wed Oct 07 2020 00:00:00 GMT+0530 (India Standard Time)
new Date(+new Date().setHours(0, 0, 0,0)+ 86400000).toLocaleDateString('fr-CA')
//"2020-10-07"
//don't forget the '+' before new Date()

Day after tomorrow

Just multiply by two ex:- 2*86400000

You can find all the locale shortcodes from https://stackoverflow.com/a/3191729/7877099


The JavaScript Date class handles this for you

var d = new Date(2012, 1, 29) // month is 0-based in the Date constructor
console.log(d.toLocaleDateString())
// Wed Feb 29 2012

d.setDate(d.getDate() + 1)
console.log(d.toLocaleDateString())
// Thu Mar 01 2012

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

Tags:

Javascript