get tomorrow's date in javascript

To get tomorrow's date in JavaScript, you can create a new Date object and use the setDate() method to set the date to the next day. Alternatively, you can use a library like Moment.js to simplify the process. Here are two examples:

Using plain JavaScript:

index.tsx
let today = new Date();
let tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);
console.log(tomorrow);
113 chars
5 lines

Using Moment.js:

index.tsx
let today = moment();
let tomorrow = today.add(1, 'days');
console.log(tomorrow);
82 chars
4 lines

ES6 provides a shorter way to achieve the same result using the spread operator:

index.tsx
let today = new Date();
let tomorrow = new Date(...today);
tomorrow.setDate(today.getDate() + 1);
console.log(tomorrow);
121 chars
5 lines

gistlibby LogSnag