diff --git a/README.md b/README.md index e74ebf0d0..c935c7ce7 100644 --- a/README.md +++ b/README.md @@ -2684,10 +2684,16 @@ getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9 ### tomorrow 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 -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')}`; +}; ```
diff --git a/docs/index.html b/docs/index.html index 431521070..f2f8b162a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -588,7 +588,13 @@ document.body📋 Copy to clipboard

getDaysDiffBetweenDates

Returns the difference (in days) between two dates.

Calculate the difference (in days) between two Date objects.

const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
   (dateFinal - dateInitial) / (1000 * 3600 * 24);
 
getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9
-

tomorrow

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.

const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0];
+

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.

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')}`;
+};
 
tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
 

Function

chainAsync

Chains asynchronous functions.

Loop through an array of functions containing asynchronous events, calling next when each asynchronous event has completed.

const chainAsync = fns => {
   let curr = 0;
diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md
index 24bbb530c..fd7c4dfa1 100644
--- a/snippets/tomorrow.md
+++ b/snippets/tomorrow.md
@@ -7,7 +7,9 @@ Use `new Date()` to get today's date, adding one day using `Date.getDate()` and
 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')}`;
+  return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(
+    t.getDate()
+  ).padStart(2, '0')}`;
 };
 ```