From 326bc26f404e8b831dc1758c2234f8133057d201 Mon Sep 17 00:00:00 2001 From: "L. Coues" Date: Thu, 11 May 2023 18:23:54 +0200 Subject: [PATCH 1/4] Accentuate month being 0-index in get month example `Date.getMonth` behavior differ slightly from the similar method as it return the index of the month and is 0-indexed, while the other method return ordinal values instead of index and don't have this distinction. One could be tempted to run `${year}-${month}-${day}` and `${hour}:${minutes}:${seconds}` after the code in exemple to get iso formated date and time but the month would be off by one as iso month are 1-indexed, january being 1 and december being 12. Adding a comment with the actual output put emphasis on this difference in behavior and might prevent people being surprised by that after the fact. The value chosen for the date is partly random. 2000 is the first year not starting with 19; January cause the month part to be 0 which should call attention to itself; 17 is high enough so it cannot be a month and I like it; 16 is in the 24h hour clock; 45 is high enough to not be confused with an hour; 30 is here for lack of imagination. --- .../web/javascript/reference/global_objects/date/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/files/en-us/web/javascript/reference/global_objects/date/index.md b/files/en-us/web/javascript/reference/global_objects/date/index.md index e9355f4db13b25d..a100a83b76c9b5d 100644 --- a/files/en-us/web/javascript/reference/global_objects/date/index.md +++ b/files/en-us/web/javascript/reference/global_objects/date/index.md @@ -325,17 +325,19 @@ date.toLocaleTimeString(); // 6:50:21 PM ### To get Date, Month and Year or Time ```js -const date = new Date(); +const date = new Date('Jan 17, 2000 16:45:30'); const [month, day, year] = [ date.getMonth(), date.getDate(), date.getFullYear(), ]; +// [0, 17, 2000] as month are 0-indexed const [hour, minutes, seconds] = [ date.getHours(), date.getMinutes(), date.getSeconds(), ]; +// [16, 45, 30] ``` ### Interpretation of two-digit years From 20779b10d1e0cdd3045dd8dffa7f74e0e5cc5d3d Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sat, 13 May 2023 18:33:41 +0800 Subject: [PATCH 2/4] Update files/en-us/web/javascript/reference/global_objects/date/index.md --- .../en-us/web/javascript/reference/global_objects/date/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/javascript/reference/global_objects/date/index.md b/files/en-us/web/javascript/reference/global_objects/date/index.md index a100a83b76c9b5d..06a07a67b6a4a61 100644 --- a/files/en-us/web/javascript/reference/global_objects/date/index.md +++ b/files/en-us/web/javascript/reference/global_objects/date/index.md @@ -325,7 +325,7 @@ date.toLocaleTimeString(); // 6:50:21 PM ### To get Date, Month and Year or Time ```js -const date = new Date('Jan 17, 2000 16:45:30'); +const date = new Date("2000-01-17"); const [month, day, year] = [ date.getMonth(), date.getDate(), From f582c83d7f9fe80f7c5147177653cae8ead3cf7c Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sat, 13 May 2023 18:39:28 +0800 Subject: [PATCH 3/4] Update files/en-us/web/javascript/reference/global_objects/date/index.md --- .../en-us/web/javascript/reference/global_objects/date/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/javascript/reference/global_objects/date/index.md b/files/en-us/web/javascript/reference/global_objects/date/index.md index 06a07a67b6a4a61..6bf31c75acdc682 100644 --- a/files/en-us/web/javascript/reference/global_objects/date/index.md +++ b/files/en-us/web/javascript/reference/global_objects/date/index.md @@ -325,7 +325,7 @@ date.toLocaleTimeString(); // 6:50:21 PM ### To get Date, Month and Year or Time ```js -const date = new Date("2000-01-17"); +const date = new Date("2000-01-17T16:45:30Z"); const [month, day, year] = [ date.getMonth(), date.getDate(), From 94e589b5b58b7e4a3de4b14db5918e58a6d89f96 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sat, 13 May 2023 18:40:30 +0800 Subject: [PATCH 4/4] Update files/en-us/web/javascript/reference/global_objects/date/index.md --- .../en-us/web/javascript/reference/global_objects/date/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/en-us/web/javascript/reference/global_objects/date/index.md b/files/en-us/web/javascript/reference/global_objects/date/index.md index 6bf31c75acdc682..e4ac4cc19faa2ea 100644 --- a/files/en-us/web/javascript/reference/global_objects/date/index.md +++ b/files/en-us/web/javascript/reference/global_objects/date/index.md @@ -325,7 +325,7 @@ date.toLocaleTimeString(); // 6:50:21 PM ### To get Date, Month and Year or Time ```js -const date = new Date("2000-01-17T16:45:30Z"); +const date = new Date("2000-01-17T16:45:30"); const [month, day, year] = [ date.getMonth(), date.getDate(),