Simple day manipulation with Javascript (without using moments
)
// Construct yesterday, today, tomorrow
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
console.log('Yesterday: ', yesterday.toDateString());
// => Yesterday: Tue May 26 2020
console.log('Today: ', today.toDateString());
// => Today: Wed May 27 2020
console.log('Tomorrow: ', tomorrow.toDateString());
// => Tomorrow: Thu May 28 2020
Top comments (0)