diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md index 9d9300071..0d16b6bbf 100644 --- a/snippets/tomorrow.md +++ b/snippets/tomorrow.md @@ -2,20 +2,17 @@ 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. +Use `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`. +Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format. ```js -const tomorrow = (long = false) => { +const tomorrow = () => { let t = new Date(); t.setDate(t.getDate() + 1); - const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( - t.getDate() - ).padStart(2, '0')}`; - return !long ? ret : `${ret}T00:00:00`; + return t.toISOString().split('T')[0]; }; ``` ```js -tomorrow(); // 2017-12-27 (if current date is 2017-12-26) -tomorrow(true); // 2017-12-27T00:00:00 (if current date is 2017-12-26) +tomorrow(); // 2018-10-18 (if current date is 2018-10-18) ```