Nono.MA

Tomorrow's date in TypeScript

NOVEMBER 2, 2022

You can get tomorrow's date in TypeScript with the Date class.

// Create a date
const tomorrow = new Date()

// Set date to current date plus 1 day
tomorrow.setDate(tomorrow.getDate() + 1)
// 2022-11-03T09:55:29.395Z

You could change that + 1 to the time delta you want to go backward or into the future.

// Create a date for Jan 2, 2020
const aDate = new Date(Date.parse("2020-01-02"))

// Go back in time three days
aDate.setDate(aDate.getDate() - 3)
new Date(aDate)
// 2019-12-30T00:00:00.000Z

// Go back in time three days
aDate.setDate(aDate.getDate() - 3)
new Date(aDate)
// 2019-12-27T00:00:00.000Z

// Go forward in time forty days
aDate.setDate(aDate.getDate() + 40)
new Date(aDate)
2020-02-05T00:00:00.000Z

BlogCodeTypescript