Files
30-seconds-of-code/snippets/tomorrow.md
Niels Leenheer 932424859b Fix tomorrow() function
For details see bug #564
2018-01-22 22:38:11 +01:00

23 lines
517 B
Markdown

### tomorrow
Results in a string representation of tomorrow's date.
Use `new Date()` to get today's date, adding one day using `Date.getDate()` and `Date.setDate()`, and converting the Date object to a string.
```js
const tomorrow = () => {
let t = new Date();
t.setDate(t.getDate() + 1);
return (
t.getFullYear() +
'-' +
String(t.getMonth() + 1).padStart(2, '0') +
'-' +
String(t.getDay()).padStart(2, '0')
);
};
```
```js
tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
```