I would like get tomorrow's date with mm/dd/yyyy format, I tried with below code. I'm able to get today's date, but tomorrow's date getting issue like "Argument of type 'number' is not assignable to parameter of type 'Date'"
const today = new Date()
let tomorrow = new Date(today);
let tomorrowDate = tomorrow.setDate(tomorrow.getDate() 1)
console.log(tomorrowDate);
CodePudding user response:
Something like that :
let currentDay = new Date();
let nextDay = currentDay.setDate(currentDay.getDate() 1);
No need for two instances of Date
To format it :
const dateFormatter = Intl.DateTimeFormat('fr-FR');
console.log(dateFormatter.format(date))
CodePudding user response:
This works too if you want in less no of lines
const d = new Date();
const day = d.getDate()
d.setDate(day 1);
const format = d.toLocaleDateString();
console.log(format);
CodePudding user response:
We can add one day of milliseconds to current day miliseconds
const today = new Date()
console.log(today.toString())
const dayInMilliSeconds = 24 * 60 * 60 * 1000
const tomorrow = new Date()
tomorrow.setMilliseconds(today.getMilliseconds() dayInMilliSeconds)
console.log(tomorrow.toString())
console.log(
`Format : ${tomorrow.getMonth() 1}/${tomorrow.getDate()}/${tomorrow.getFullYear()}`
)