549 B
549 B
title, tags
| title | tags |
|---|---|
| daysFromNow.md | date,beginner |
Returns the date of n days from today as a string representation.
- Use
new Date()andDate.prototype.getDate()to get the current time stamp add the number of milliseconds and use it to create a newDateobject. - Use
Date.prototype.toISOString()to return a string inyyyy-mm-ddformat.
const daysFromNow = n =>{
let date = new Date(new Date().getTime() + n * 24 * 60 * 60 * 1000);
return date.toISOString().split('T')[0];
}
daysFromNow('5'); // 2020-10-13