Merge pull request #565 from NielsLeenheer/master
[FIX: #564] Fix inaccurate tomorrow() function
This commit is contained in:
@ -1,10 +1,14 @@
|
|||||||
### tomorrow
|
### tomorrow
|
||||||
|
|
||||||
Results in a string representation of tomorrow's date.
|
Results in a string representation of tomorrow's date.
|
||||||
Use `new Date()` to get today's date, adding `86400000` of seconds to it(24 hours), using `Date.toISOString()` to convert Date object to string.
|
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
|
```js
|
||||||
const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
|
const tomorrow = () => {
|
||||||
|
let t = new Date();
|
||||||
|
t.setDate(t.getDate() + 1);
|
||||||
|
return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(t.getDate()).padStart(2, '0')}`;
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user