get the date 5 days from now in javascript

To get the date 5 days from now in JavaScript, you can create a new Date object and add 5 days to it using the setDate() method. Here's an example:

index.tsx
let now = new Date();
let nextWeek = new Date(now.setDate(now.getDate() + 5));
79 chars
3 lines

In this example, now is the current date and time. The setDate() method is used to add 5 days to the current date. The resulting date is stored in the nextWeek variable.

You can then format the date as a string using the toLocaleString() method:

index.tsx
console.log(nextWeek.toLocaleString());
40 chars
2 lines

This will output the date and time as a string in your local time zone. For example: "6/17/2021, 6:23:15 PM"

gistlibby LogSnag