Created
October 31, 2024 05:46
-
-
Save mribbons/7bd3e4f9eb9a5fe733d3bd6ff3eff4fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let [ year, month, day ] = [2024, 9, 12] | |
| let scaryDate = new Date() | |
| scaryDate.setFullYear(year) | |
| scaryDate.setMonth(month - 1) // set month input is zero based | |
| scaryDate.setDate(day) | |
| console.log(`π¦`, scaryDate, `π¦`) | |
| // output: | |
| // π¦ 2024-10-12T05:36:21.947Z π¦ | |
| // October?? let's take a look at the setMonth docs: (emojis added for effect) | |
| /** | |
| * Sets the month value in the Date object using local time. | |
| * @param month A numeric value equal to the month. The value for January is 0, and other month values follow consecutively. | |
| * @param date A numeric value representing the day of the month. πππ If this value is not supplied, the value from a call to the getDate method is used πππ. | |
| */ | |
| let goodDate = new Date() | |
| goodDate.setFullYear(year) | |
| goodDate.setMonth(month - 1, day) // provide the date as well, just as you would completely not expect. | |
| goodDate.setDate(day) | |
| console.log(`π `, goodDate, `π `) | |
| // output: | |
| // π 2024-09-12T06:36:21.947Z π |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment